Các bác giúp em đánh số thứ tự bằng code với ạ! (2 người xem)

Liên hệ QC

Người dùng đang xem chủ đề này

trungtamcnc

Thành viên hoạt động
Tham gia
5/4/10
Bài viết
124
Được thích
9
Ban đầu

Câu i: fkadfhjhfs
Câu i: lfjdhf
Câu i: kdfjdjfd
Câu i: fkadfhjhfs
Câu i: lfjdhf
Câu i: kdfjdjfd
Câu i: fkadfhjhfs
Câu i: lfjdhf
Câu i: kdfjdjfd

Sản phẩm
Câu 1: fkadfhjhfs
Câu 2: lfjdhf
Câu 3: kdfjdjfd
Câu 4: fkadfhjhfs
Câu 5: lfjdhf
Câu 6: kdfjdjfd
Câu 7: fkadfhjhfs
Câu 8: lfjdhf
Câu 9: kdfjdjfd

Mong các bác giúp đỡ! Em xin cảm ơn.
 
Ai biết dữ liệu bạn nằm tại cột nào, từ dòng nào mà viết code chứ? Vì cớ vì bạn không đưa file lên?
 
Ban đầu

Câu i: fkadfhjhfs
Câu i: lfjdhf
Câu i: kdfjdjfd
Câu i: fkadfhjhfs
Câu i: lfjdhf
Câu i: kdfjdjfd
Câu i: fkadfhjhfs
Câu i: lfjdhf
Câu i: kdfjdjfd

Sản phẩm
Câu 1: fkadfhjhfs
Câu 2: lfjdhf
Câu 3: kdfjdjfd
Câu 4: fkadfhjhfs
Câu 5: lfjdhf
Câu 6: kdfjdjfd
Câu 7: fkadfhjhfs
Câu 8: lfjdhf
Câu 9: kdfjdjfd

Mong các bác giúp đỡ! Em xin cảm ơn.

Gửi bạn một cách trong excel http://upfile.vn/iPb5/Thay_The.xls
 
Em tự làm không có vòng lặp thì code nó dài quá! Mới đến câu 15 mà đã như vậy. Mong các bác quan tâm.

Sub a1DanhsothutuCau()
'
'
'
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Câu ^?:"
.Replacement.Text = "Câu i:"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "Câu ^?^?:"
.Replacement.Text = "Câu i:"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll


Selection.Find.Replacement.Font.Bold = True
Selection.Find.Execute
With Selection.Find
.Text = "Câu i:"
.Replacement.Text = "Câu 1:"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With

With Selection.Find
.Text = "Câu i:"
.Replacement.Text = "Câu 2:"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With




With Selection.Find
.Text = "Câu i:"
.Replacement.Text = "Câu 3:"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With



With Selection.Find
.Text = "Câu i:"
.Replacement.Text = "Câu 4:"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With



With Selection.Find
.Text = "Câu i:"
.Replacement.Text = "Câu 5:"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With




With Selection.Find
.Text = "Câu i:"
.Replacement.Text = "Câu 6:"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With




With Selection.Find
.Text = "Câu i:"
.Replacement.Text = "Câu 7:"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With




With Selection.Find
.Text = "Câu i:"
.Replacement.Text = "Câu 8:"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With





With Selection.Find
.Text = "Câu i:"
.Replacement.Text = "Câu 9:"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With




With Selection.Find
.Text = "Câu i:"
.Replacement.Text = "Câu 10:"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With




With Selection.Find
.Text = "Câu i:"
.Replacement.Text = "Câu 11:"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With




With Selection.Find
.Text = "Câu i:"
.Replacement.Text = "Câu 12:"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With





With Selection.Find
.Text = "Câu i:"
.Replacement.Text = "Câu 13:"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With




With Selection.Find
.Text = "Câu i:"
.Replacement.Text = "Câu 14:"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With




With Selection.Find
.Text = "Câu i:"
.Replacement.Text = "Câu 15:"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With



End Sub
 
Cảm ơn bác, nhưng em lại cần trong Word.
word hay ex cũng là văn bản cần in ra và thống kê, tại sao phải làm trong word cho nó khó khăn, cứ excel mà làm, còn như bác cứ muốn trong word thì bác tự làm, làm được đến đâu dùng đến đó.
 
Lần chỉnh sửa cuối:
word hay ex cũng là văn bản cần in ra và thống kê, tại sao phải làm trong word cho nó khó khăn, cứ excel mà làm, còn như bác cứ muốn trong word thì bác tự làm, làm được đến đâu dùng đến đó.

Em dùng word để thiết kế đề thi trắc nghiệm. Phục vụ công việc đặc thù. E muốn nhìn thấy ai viết được code của cái vòng lặp.
 
Web KT

Bài viết mới nhất

Back
Top Bottom