excel - VBA macro to delete a row -
hey created macro added headers deleted info , got data formatted noticed when ran file deleted data in exact cell need same delete row phrase sits on
imagine had cell a1 in other versions of document phrase in a2 macro delete whats in a1
the phrase zfd , whatever cell in need macro delete entire row phrase sits on helppppp
sub umr() ' ' umr macro ' ' range("a1").select activecell.formular1c1 = "transaction_type" range("b1").select activecell.formular1c1 = "meter_point_ref" range("c1").select activecell.formular1c1 = "actual_read_date" range("d1").select activecell.formular1c1 = "meter_reading_source" range("e1").select activecell.formular1c1 = "meter_reading_reason" range("f1").select activecell.formular1c1 = "meter_serial_number" range("g1").select activecell.formular1c1 = "meter_reading" range("h1").select activecell.formular1c1 = "meter_roc_count" range("i1").select activecell.formular1c1 = "meter_read_verified" range("j1").select activecell.formular1c1 = "corrector_serialnumber" range("j1").select activecell.formular1c1 = "corrector_serial_number" range("k1").select activecell.formular1c1 = "corrector_uncorrected_reading" range("l1").select activecell.formular1c1 = "corrector_corrected_reading" range("m1").select activecell.formular1c1 = "corrector_roc_count" range("n1").select activecell.formular1c1 = "corrector_usable_ind" range("o1").select activecell.formular1c1 = "corrector_read_verified" range("a17").select selection.clearcontents range("b17").select selection.clearcontents columns("c:c").columnwidth = 8.29 columns("c:c").entirecolumn.autofit columns("b:b").entirecolumn.autofit columns("a:a").entirecolumn.autofit columns("e:e").select columns("d:d").entirecolumn.autofit columns("e:e").entirecolumn.autofit columns("f:f").entirecolumn.autofit columns("g:g").entirecolumn.autofit columns("h:h").entirecolumn.autofit activewindow.scrollcolumn = 2 activewindow.scrollcolumn = 3 columns("i:i").entirecolumn.autofit columns("j:j").entirecolumn.autofit range("q1").select columns("k:k").entirecolumn.autofit columns("l:l").entirecolumn.autofit range("r1").select columns("m:m").entirecolumn.autofit columns("n:n").entirecolumn.autofit columns("o:o").entirecolumn.autofit activewindow.smallscroll down:=6 activewindow.smallscroll toright:=-9 activewindow.smallscroll down:=-88 end sub
as did have time reorganized code little. aware not commonly done here on stackoverflow. next time: @ least try code something, if it's wrong that's not problem, that's can help. , information: quite newby (3,5 months of vba far), it's not hard. if code not perfected yet, of time can work somehow...
try once (read comments in code first):
sub umr() dim ws worksheet set ws = acitveworkbook.activeworksheet 'be aware run on activesheet dim values variant values = array("transaction_type", "meter_point_ref", "actual_read_date", "meter_reading_source", "meter_reading_reason", "meter_serial_number", "meter_reading", "meter_roc_count", "meter_read_verified", "corrector_serialnumber", "corrector_serial_number", "corrector_uncorrected_reading", "corrector_corrected_reading", "corrector_roc_count", "corrector_usable_ind", "corrector_read_verified") dim findstring string findstring = "zfd" dim zfdval variant dim irow integer dim icol integer set zfdval = ws.find(what:=findstring, _ after:=ws.cells(ws.cells.count), _ lookin:=xlvalues, _ lookat:=xlwhole, _ 'if value part of cell xlpart instead of xlwhole searchorder:=xlbyrows, _ searchdirection:=xlnext, _ matchcase:=false) 'if want match string (regarding capital letters) you'll have set true irow = range(zfdval.adress).row 'this untested... icol = 1 (ubound(values)-lbound(values)) ws.cells(irow, icol) = values(icol-1) next icol range("a17").clear ' believe unintendet , recorded alongside can delete these 2 rows... range("b17").clear columns("a:o").entirecolumn.autofit end sub
if run-time error please press "debug" , comment line gets marked yellow. way can correcting code...
Comments
Post a Comment