I have a form button in a sheet MasterList! when clicked it copies certain ranges from MasterList! to wsh Cab_Sch.
The code as below first clears the contents in Cab_Sch and then copies the values from MasterList!.
I have also a formula in col H ( and may be in I and J in future) and Drop down list in col M
I dont want the formula and drop down lists to be cleared . Only the values are to be cleared.
If for example, 4 rows are copied from MasterList! to Cab_Sch, the the formulas and dropdown lists are also to be copied in these four rows.
For the next click, if only two rows are copied from Masterlist! to cab_Sch then the formulas are copied in only two rows.
Please advise, Best regards
Vilas desai
Code: Select all
Sub UpdateCabSch()
Dim r As Long
Dim m As Long
Dim t As Long
Application.ScreenUpdating = False
Worksheets("Cab_Sch").Range("A5:G50000,I5:V50000").Clear
t = 4
m = Range("W" & Rows.Count).End(xlUp).Row
For r = 5 To m
If Range("I" & r).Value <> 0 Then
t = t + 1
'Device
Range("D" & r).Copy
Worksheets("Cab_Sch").Range("A" & t).PasteSpecial Paste:=xlPasteValues
'Device Tag
Range("J" & r).Copy
Worksheets("Cab_Sch").Range("B" & t).PasteSpecial Paste:=xlPasteValues
'Service Area
Range("B" & r).Copy
Worksheets("Cab_Sch").Range("C" & t).PasteSpecial Paste:=xlPasteValues
'Loop Number
Range("H" & r).Copy
Worksheets("Cab_Sch").Range("D" & t).PasteSpecial Paste:=xlPasteValues
'No of Wires
Range("I" & r).Copy
Worksheets("Cab_Sch").Range("E" & t).PasteSpecial Paste:=xlPasteValues
'IO Type
Range("W" & r).Copy
Worksheets("Cab_Sch").Range("G" & t).PasteSpecial Paste:=xlPasteValues
'Jn Box ID
Range("K" & r).Copy
Worksheets("Cab_Sch").Range("K" & t).PasteSpecial Paste:=xlPasteValues
'Cable Tag
Range("M" & r).Copy
Worksheets("Cab_Sch").Range("N" & t).PasteSpecial Paste:=xlPasteValues
'Marshalling Rack ID
Range("N" & r).Copy
Worksheets("Cab_Sch").Range("R" & t).PasteSpecial Paste:=xlPasteValues
'PLC Rack No
Range("T" & r).Copy
Worksheets("Cab_Sch").Range("V" & t).PasteSpecial Paste:=xlPasteValues
End If
Next r
Application.ScreenUpdating = True
End Sub