Please assist in modifying my macro with a set range

Phisig500

New Member
Joined
Mar 13, 2015
Messages
8
After hours or struggle (albeit a great learning experience), I finished the below Macro. The macro basically checks a column for text in each cell, and if text has been entered, it copy's and pastes special the line (s) on a new sheet. The issue I am having is that I have slicers in column A of my worksheet therefore all the cells are blank. When I run the macro it finds the last row, but then stops because it moves to column A, which is blank, and then stops. The range that I need to the macro to run in for this particular sheet is B1:W113, but i do not know quite how to change it to limit it to the specific rage. If anyone can help, it would be greatly appreciated.


Thank you!!


Sub TestagainSAFE()
Dim i As Long
Dim lr1 As Long, lr2 As Long
Dim Delta As String
Dim wks1 As Worksheet, wks2 As Worksheet
Set wks1 = Worksheets("Sheet1")
Set wks2 = Worksheets("Sheet2") 'change to suit
lr1 = wks1.Cells(Rows.Count, "B").End(xlUp).Row
For i = 2 To lr1
Delta = wks1.Cells(i, "Y").Value
If Not IsEmpty(Len(Delta)) Then
If Len(Delta) <> 0 Then
lr2 = wks2.Cells(Rows.Count, "A").End(xlUp).Row + 1
wks1.Cells(i, "B").EntireRow.Copy
wks2.Cells(lr2, "A").PasteSpecial Paste:=xlPasteValues
End If
End If
Next i
MsgBox "SPI financial inquiries have been submitted", vbInformation
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Interpreting your description to mean that you want rows pasted, starting in column "B" of the second sheet, you can try the following:

Code:
Dim i As Long
 Dim lr1 As Long, lr2 As Long
 Dim Delta As String
 Dim x As Integer
 Dim wks1 As Worksheet, wks2 As Worksheet
 Set wks1 = Worksheets("Sheet1")
 Set wks2 = Worksheets("Sheet2") 'change to suit
 lr1 = wks1.Cells(Rows.Count, "B").End(xlUp).Row
 For i = 2 To lr1
 Delta = wks1.Cells(i, "Y").Value
 'If Not IsEmpty(Len(Delta)) Then
 If Len(Delta) <> 0 Then
 lr2 = wks2.Cells(Rows.Count, "B").End(xlUp).Row + 1
 x = wks1.Cells(i, "B").EntireRow.Columns.Count - 5
 wks1.Range(Cells(i, "B"), Cells(i, x)).Copy
 wks2.Cells(lr2, "B").PasteSpecial Paste:=xlPasteValues
 End If
 'End If
 Next i
 MsgBox "SPI financial inquiries have been submitted", vbInformation
 Application.CutCopyMode = False
 
Upvote 0

Forum statistics

Threads
1,215,460
Messages
6,124,949
Members
449,198
Latest member
MhammadishaqKhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top