Temukan dan ganti makro nilai sel

Temukan dan ganti makro nilai sel

Isu

Saya memiliki 20 rumus ini (1 per kode saham) di spreadsheet saya yang berasal dari etrade

= PROStaticData (2, "mqg.ASX", "2010/08/10; 2010/08/19; 3; Benar; Salah", "10")

saya ingin dapat mengubah tanggal sekaligus, saya memiliki 2 sel yang mengatur nilai yang ingin saya cari berada di M8 dan M9 dan saya ingin menggantinya dengan nilai masing-masing di L8 dan L9 dan ini berfungsi dengan baik di mana saja dalam spreadsheet kecuali dalam rumus di atas karena alasan tertentu tidak akan melihat rumus untuk itu berikut ini adalah kode yang saya gunakan.

 Sub theone () 'Selection.Replace What: = "ValueToFind", Penggantian: = Range ("A1"). Value, LookAt: = xlPart, SearchOrder: = xlByRows, MatchCase: = False, SearchFormat: = False, ReplaceFormat: = False 'Range ("B1: B2"). Pilih Selection.Copy Range ("L8: L9"). Pilih Selection.PasteSpecial Paste: = xlPasteValues, Operasi: = xlNone, SkipBlanks _: = False, Transpose: = False Range ("L1: B2") "M8"). Pilih Application.CutCopyMode = Pilihan Salah. Rentang Salinan ("L8"). Pilih Application.CutCopyMode = Pilihan Salah. Sel Salin. Ganti Apa: = Rentang ("M8"). Nilai, Penggantian: = Rentang ( "L8"). Value, LookAt: = _ xlPart, SearchOrder: = xlByRows, MatchCase: = False, SearchFormat: = False, _ ReplaceFormat: = False Cell. Ganti What: = Range ("M9"). Nilai, Penggantian: = Range ("L9"). Value, LookAt: = _ xlPart, SearchOrder: = xlByRows, MatchCase: = False, SearchFormat: = False, _ GantiFormat: = False Range ("L8: L9"). Pilih Application.CutCopyMode = Seleksi Salah. Rentang Salinan ("M8: M9"). Pilih Sub ActiveSheet.Paste End 

Larutan

Berikut beberapa keraguan di makro Anda

Contoh

 Range ("M8"). Pilih Application.CutCopyMode = Pilihan Salah.Copi 

Anda menyalin nilai ini, tetapi tidak pernah menempel dan sama dengan blok selanjutnya dengan L8. Mungkin kode tidak diperlukan atau mungkin Anda lupa menempelkan. Alasan Anda tidak dapat menggantinya karena, tanggal dalam rumus adalah dalam format YYYY / MM / DD. Tanggal yang Anda cari tidak dalam format itu. Jadi, Anda perlu menambahkan satu pencarian lagi dan ganti tempat Anda mencari tanggal dalam format YYYY / MM / DD dan ganti dengan yang sama

 Cells.Replace What: = FORMAT (Range ("M8"). Nilai, "YYYY / MM / DD"), Penggantian: = FORMAT (Range ("L8"). Nilai, "YYYY / MM / DD"), LookAt : = _ xlPart, SearchOrder: = xlByRows, MatchCase: = False, SearchFormat: = False, _ GantiFormat: = False 

Ini barang-barang yang Anda ulangi.

 Sub theone () Dim sDateFind As String Dim sDateRep As String Range ("B1: B2"). Pilih Selection.Copy Range ("L8: L9"). Pilih Selection.PasteSpecial Paste: = xlPasteValues, _ Operation: = xlNone, _ SkipBlanks: = False, _ Transpose: = False Range ("M8"). Pilih Application.CutCopyMode = Pilihan Salah.Rentang Salinan ("L8"). Pilih Application.CutCopyMode = Pilihan Salah.Copi sDateFind = Range ("M8") .Nilai sDateRep = Rentang ("L8"). Nilai Sel. Ganti Apa: = Rentang ("M8"). Nilai, _ Penggantian: = Rentang ("L8"). Nilai, _ LookAt: = xlPart, _ SearchOrder: = xlByRows, _ MatchCase: = False, _ SearchFormat: = False, _ ReplaceFormat: = False Cells.Replace What: = Format (sDateFind, "yyyy / mm / dd"), _ Penggantian: = Format (sDateRep, "yyyy / mm / dd "), _ LookAt: = xlPart, _ SearchOrder: = xlByRows, _ MatchCase: = False, _ SearchFormat: = False, _ ReplaceFormat: = False sDateFind = Range (" M9 "). Nilai sDateRep = Range (" L9 ") .Nilai Sel. Ganti Apa: = Rentang (" M9 "). Nilai, _ Penggantian: = Rentang (" L9 "). Nilai, _ LookAt: = xlPart, _ PencarianOrder: = xlByRows, _ MatchCase: = Salah, _ SearchFormat: = Salah, _ ReplaceFormat: = Sel Salah. Ganti Apa: = Format (sDateFind, "yyyy / mm / dd"), _ Penggantian: = Format (sDateRep, "yyyy / mm / dd"), _ LookAt : = xlPart, _ SearchOrder: = xlByRows, _ MatchCase: = False, _ SearchFormat: = False, _ ReplaceFormat: = False Range ("L8: L9"). Pilih Application.CutCopyMode = Pilihan Salah. Rentang Salinan ("M8:: M9 "). Pilih ActiveSheet.Paste End Sub 

Catatan

Dipecahkan oleh rizvisa1

Artikel Sebelumnya Artikel Berikutnya

Tips