Code for Multiple Sheet/Active Sheet - vba

i'm currently working on a code that will copy data from one sheet to another (please see below),it currently works on one sheet, but now I want this code to work on multiple sheets or whatever sheet is active. Can you please assist me in modifying this code to work on multiple sheets.
Sub sbCopyRangeToAnotherSheet()
Sheets("Sheet1").Select
Range("A15:E188").Select
Selection.ClearContents
Range("A15").Select
Sheets("FCI").Select
Range("C51").Select
'Copy the data
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
'Activate the destination worksheet
Sheets("Sheet1").Activate
'Select the target range
Range("A15").Select
'Paste in the target destination
Sheets("Sheet1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
End Sub

May be this is what you are looking for, also you can yourself twick the code little bit to suit your requirements.
Sub sbCopyRangeToAnotherSheet()
temp = ActiveSheet.Index
Sheets(temp).Select
Range("A15:E188").Copy
Worksheets("Sheet1").Activate
k = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
Range("A" & k + 1).Select ' kindly change the code to suit your paste location
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub

modified your code with a loop to go through all the sheets present in workbook.
let me know if this is what was required.
Sub sbCopyRangeToAnotherSheet()
Sheets("Sheet1").Select
Range("A15:E188").Select
Selection.ClearContents
Range("A15").Select
Sheets("FCI").Select
Range("C51").Select
'Copy the data
For Each Sheet In ActiveWorkbook.Sheets
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
'Activate the destination worksheet
Sheets("Sheet1").Activate
'Select the target range
Range("A15").Select
'Paste in the target destination
Sheets("Sheet1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Next
End Sub

as I understand by your code, you want to be able to copy data from any active sheet to FSI Sheet. if this is the case , I have done changes as in below code.
Sub sbCopyRangeToAnotherSheet()
temp = ActiveSheet.Index
Sheets(temp).Select
Range("A15:E188").Select
Selection.ClearContents
Range("A15").Select
'Sheets("FCI").Select
'ActiveSheet.Range("C51").Select
'Copy the data
'For k = 1 To ActiveWorkbook.Worksheets.Count
Worksheets(temp).Activate
Sheets(temp).Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
'Activate the destination worksheet
Sheets(temp).Activate
'Select the target range
Range("A15").Select
'Paste in the target destination
Sheets("FCI").Select
Range("A15").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
'Next
End Sub

Related

Macro to copy data from one workbook to another

I'm struggling with a macro that I'm trying to create that will pull data into a Master workbook from a different workbook that is updated weekly.
The problem I'm having is that the file I receive weekly is always named differently (updated for the week ending) and 7 of the 8 tabs in the workbook are also named differently (one for each day of the week that applies in that week ending range).
If it was a static file name, the macro is a piece of cake and works perfectly. I've read a great deal on a number of forums about how you can set it the macro to look at an ACTIVE workbook, rather than a specifically named one, but I just can't seem to get that to work.
Below is my macro for the specifically name file; what do I need to do differently so that I can run it on the file I receive each week just by having it open and active?
Sub SecData()
'
' SecData Macro
' Macro to move security badge-in data from weekly file to Master Security Log workbook. Will overwrite Sheet1
'
'
Sheets("Sheet1").Select
Range("D2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.EntireRow.Delete
Range("A2").Select
Windows("Framingham counts for the week ending 06-02-18.xlsx").Activate
Sheets("05-27").Select
Range("D2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToLeft)).Select
Selection.Copy
Windows("Master Security Logs.xlsx").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A13").Select
Windows("Framingham counts for the week ending 06-02-18.xlsx").Activate
Sheets("05-28").Select
Range("D2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToLeft)).Select
Application.CutCopyMode = False
Selection.Copy
Windows("Master Security Logs.xlsx").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=18
Range("A32").Select
Windows("Framingham counts for the week ending 06-02-18.xlsx").Activate
Sheets("05-29").Select
Range("D2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToLeft)).Select
Range(Selection, Selection.End(xlUp)).Select
Application.CutCopyMode = False
Selection.Copy
Windows("Master Security Logs.xlsx").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("D32").Select
Selection.End(xlDown).Select
ActiveWindow.SmallScroll Down:=18
Range("A2154").Select
Windows("Framingham counts for the week ending 06-02-18.xlsx").Activate
Sheets("05-30").Select
Range("D2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToLeft)).Select
Application.CutCopyMode = False
Selection.Copy
Windows("Master Security Logs.xlsx").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("D2154").Select
Selection.End(xlDown).Select
ActiveWindow.SmallScroll Down:=9
Range("A4378").Select
Windows("Framingham counts for the week ending 06-02-18.xlsx").Activate
Sheets("05-31").Select
Range("D2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToLeft)).Select
Application.CutCopyMode = False
Selection.Copy
Windows("Master Security Logs.xlsx").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("D4378").Select
Selection.End(xlDown).Select
ActiveWindow.SmallScroll Down:=12
Range("A6638").Select
Windows("Framingham counts for the week ending 06-02-18.xlsx").Activate
Sheets("06-01").Select
Range("D2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToLeft)).Select
Application.CutCopyMode = False
Selection.Copy
Windows("Master Security Logs.xlsx").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("D6638").Select
Selection.End(xlDown).Select
ActiveWindow.SmallScroll Down:=18
Range("A8435").Select
Windows("Framingham counts for the week ending 06-02-18.xlsx").Activate
Sheets("06-02").Select
Range("D2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToLeft)).Select
Application.CutCopyMode = False
Selection.Copy
Windows("Master Security Logs.xlsx").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ScrollRow = 7397
ActiveWindow.ScrollRow = 2466
ActiveWindow.ScrollRow = 1
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("Sheet1").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").AutoFilter.Sort.SortFields.Add Key:=Range _
("A1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveWorkbook.Worksheets("Sheet1").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").AutoFilter.Sort.SortFields.Add Key:=Range _
("B1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
#Lacey LaDue, I can't really make good sense of the copy and paste ranges but I know what you are doing, defining the range of the copy sheet, selected a cell in your master sheet and pasting it in.
365 tabs? I thought you were doing this weekly?
You could always copy tab (worksheets) themselves but it looks like you are putting a weeks data on a single master sheet page.
Here is the frame work in one sub (macro) but I did not perform the copy and paste for each worksheet into your master worksheet / workbook, but this gets you close as it shows you how to get the file, open the file, and then walk through the worksheets 1 at a time and perform tasks on them.
I would need to know more about the copysheet and the master sheet to do the detail work. I hop this helps you out. I am guessing your macro code is from the macro recorder because of all of the selects.
Option Explicit
'Sub to get the Current urFileName
Private Sub getFN()
Dim Finfo As String
Dim FilterIndex As Long
Dim Title As String
Dim CopyBook As Workbook 'Workbook to copy from
Dim CopySheet As Worksheet 'Worksheet to copy from
Dim FN As Variant 'File Name
Dim wsNum As Double 'worksheet # as you move through the Copy Book
Dim cwsLastRow As Long 'copy worksheet last row
Dim mwsLastRow As Long 'master worksheet last row
Dim masterWS As Worksheet 'thisworkbook, your master worksheet
Set masterWS = ThisWorkbook.Worksheets("Master Security Logs")
'Set up file filter
Finfo = "Excel Files (*.xls*),*.xls*"
'Set filter index to Excel Files by default in case more are added
FilterIndex = 1
' set Caption for dialogue box
Title = "Select the Current AP Reconcile Workbook"
'get the Forecast Filename
FN = Application.GetOpenFilename(Finfo, FilterIndex, Title)
'Handle file Selection
If FN = False Then
MsgBox "No file was selected.", vbExclamation, "Not so fast"
Else
'Do your Macro tasks here
'Supress Screen Updating but don't so this until you know your code runs well
Application.ScreenUpdating = False
'Open the AP File
Workbooks.Open (FN)
'Hide the file so it is out of the way
Set CopyBook = ActiveWorkbook
For wsNum = 1 To CopyBook.Sheets.Count 'you stated there will be 8, this is safer
'Do your work here, looks like you are copying certain ranges from wach sheet into ThisWorkbook
CopySheet = CopyBook.Worksheets(wsNum) '1,2,3,4,5,6,7,8
'Finds the lastRow in your Copysheet each time through
cwsLastRow = CopySheet.Cells(CopySheet.Rows.Count, "A").End(xlUp).Row
'so you would have to keep tabs on what the lastRow of this sheet is too and always start at +1
mwsLastRow = masterWS.Cells(masterWS.Rows.Count, "A").End(xlUp).Row
'Do some copy and pasting between copySheet and masterWS based on your ranges
'It looks like you copy data from each ws into your single master book worksheet
'Clear the clipboard before you go around again
Application.CutCopyMode = False
Next wsNum
End If
'Close the workbook opened for the copy
CopyBook.Close savechanges:=False 'Not needed now
'Screen Updating Back on
Application.ScreenUpdating = True
End Sub

VBA - How to filter and copy the data from pivot table?

Good Day! Let say I have this Pivot table in my excel. From image below, I want to filter BrandA and copy all brand BrandA and paste it into new Sheet the same goes to BrandX and BrandZ.
Please help me :(
Thank you!
EDITED 1
Below is my recorded macro.
Sub MacroTest2()
With ActiveSheet.PivotTables("PivotTable3").PivotFields("Brand")
.PivotItems("BrandA").Visible = False
.PivotItems("BrandZ").Visible = False
End With
Range("A4").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets.Add After:=ActiveSheet
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Pivot").Select
ActiveSheet.PivotTables("PivotTable3").PivotFields("Brand").ClearAllFilters
With ActiveSheet.PivotTables("PivotTable3").PivotFields("Brand")
.PivotItems("BrandX").Visible = False
.PivotItems("BrandZ").Visible = False
End With
Range("A4").Select
Range(Selection, Selection.End(xlToRight)).Select
Application.CutCopyMode = False
Selection.Copy
Sheets.Add After:=ActiveSheet
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Pivot").Select
ActiveSheet.PivotTables("PivotTable3").PivotFields("Brand").ClearAllFilters
With ActiveSheet.PivotTables("PivotTable3").PivotFields("Brand")
.PivotItems("BrandA").Visible = False
.PivotItems("BrandX").Visible = False
End With
Range("A4:A5").Select
Range(Selection, Selection.End(xlToRight)).Select
Application.CutCopyMode = False
Selection.Copy
Sheets.Add After:=ActiveSheet
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Pivot").Select
End Sub

Looping though only selected sheets to proceed several steps

I have an Excel file which contains several sheets where I have to cut-copy from one column to another.
When I use the code on one specific sheet it works perfectly, yet while I've already tried to use e.g. Sheets(Array("ThisSheet", "ThatSheet")).Select and it worked partially, because after row 131 it pastes the cut data in the wrong direction, which is odd. Nonetheless, no idea how to solve it.
Could you please help me with the code? I'd trupy appreciate it. In the comments you can find names of the specific columns only, so please simply ingore it.
Sub TABFixLoop_Main()
' TABFix Macro Loop Core Scratch
' === Declaces which tabs are in the loop ========
' === Exceptions: ES20, IT40, IT43, IT44, IT45, PT20 ===
Application.ScreenUpdating = False
Dim ws As Worksheet
Dim Sheets As Range
Set Sheets = Sheets(Array("BE00", "CH10", "CZ00", "DK00", "ES00", "FI00", "IT00", "LU30", "NL00", "NO00", "PT00", "SE00"))
For Each ws In Sheets
Do
' Fit the columns size
ws.Activate
ws.Columns.AutoFit
' Putting value ranges in correct places:
' MMDoc #
Range("P5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Range("N5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ws.Columns("N:N").Select
Selection.NumberFormat = "0"
Range("P5").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.ClearContents
' Age
Range("Q5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Range("O5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range("Q5").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.ClearContents
' PO Vendor
Range("R5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Cut
Application.CutCopyMode = False
Selection.Copy
Range("P5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range("P5").NumberFormat = "0"
Range("R5").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.ClearContents
' Business Area
Range("S5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Range("R5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range("S5").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.ClearContents
' Remove empty columns
ws.Columns("S:T").Select
Selection.Delete Shift:=xlToLeft
' Add formula to count aging ranges
Range("U5").Select
ActiveCell.FormulaR1C1 = "=+IF(RC[-6]<=30,""0-30"",IF(RC[-6]<=60,""31-60"",IF(RC[-6]<=90,""61-90"",IF(RC[-6]<=120,""91-120"",IF(RC[-6]<=180,""121-180"",IF(RC[-6]<=365,""181-365"",IF(RC[-6]>365,"">365"","""")))))))"
Range(Selection, Selection.End(xlDown)).Select
Selection.FillDown
Loop Until ws = Sheets(Sheets.Count).Active
Application.ScreenUpdating = True
End Sub
Sub test()
Dim ws As Worksheet
For Each ws In Worksheets
Select Case ws.Name
Case "BE00", "CH10", "CZ00", "DK00", "ES00", "FI00", "IT00", "LU30", "NL00", "NO00", "PT00", "SE00"
ws.Columns.AutoFit
shiftdata ws, "P", "N"
shiftdata ws, "Q", "O"
shiftdata ws, "R", "P"
With ws.Range("U5")
.FormulaR1C1 = "=+IF(RC[-6]<=30,""0-30"",IF(RC[-6]<=60,""31-60"",IF(RC[-6]<=90,""61-90"",IF(RC[-6]<=120,""91-120"",IF(RC[-6]<=180,""121-180"",IF(RC[-6]<=365,""181-365"",IF(RC[-6]>365,"">365"","""")))))))"
.Copy Destination := ws.Range(.Address & ":" & .End(xlDown).Address)
End With
Case Else
End Select
Next ws
End Sub
Sub shiftdata(ws As Worksheet, strFrom As String, StrTo As String)
Dim r As Range
Set r = ws.Range(strFrom & "5:" & strFrom & ws.Range(strFrom & "5").End(xlDown).Row)
r.Copy
ws.Range(StrTo & "5").PasteSpecial xlPasteValues
r.ClearContents
End Sub

Excel VBA ClearContents error

Im trying to run macro which should clear contents from sheets AA, BB and CC and then move into sheet MENU but its highliting me an error on line 4. Please see the code below.
Sub clear_sheets()
Snames = Split(AA, BB, CC)
For Count = 0 To UBound(Snames)
Sheets(Snames(Count)).Range("A3:C3").End(xlDown).ClearContents
Next
Sheets("MENU").Select
Optimise (False)
End Sub
I got a little bit different approach posted on a different forum. Which would run more efficiently, I mean which one will will be putting less stress on a processing?
Sub clear_sheets()
Optimise (True)
Snames = Split("AA, BB, CC", ", ")
For count = 0 To UBound(Snames)
MyRange = Range("A3:C3", Range("A3:C3").End(xlDown)).Address
ThisWorkbook.Sheets(Snames(count)).Range(MyRange).ClearContents
Next
Sheets("MENU").Select
Optimise (False)
End Sub
Update
I understand this is not a code writing website but I would like to ask you if you could have a look at my code below.
Sub distribute_dsp_data_9()
Sheets("raw_data_1_9").Visible = True
Sheets("raw_data_1_9").Select
ActiveSheet.ListObjects("COMP_summ_9").Range.AutoFilter Field:=2, Criteria1 _
:="DTTD"
Range("C2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToLeft)).Select
Selection.Copy
Sheets("DTTD").Select
Range("A3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("raw_data_1_9").Select
ActiveSheet.ListObjects("COMP_summ_9").Range.AutoFilter Field:=2, Criteria1 _
:="FDTL"
Range("C2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToLeft)).Select
Selection.Copy
Sheets("FDTL").Select
Range("A3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("raw_data_1_9").Select
ActiveSheet.ListObjects("COMP_summ_9").Range.AutoFilter Field:=2, Criteria1 _
:="FULL"
Range("C2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToLeft)).Select
Selection.Copy
Sheets("FUL ON").Select
Range("A3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("raw_data_1_9").Select
ActiveSheet.ListObjects("COMP_summ_9").Range.AutoFilter Field:=2
Sheets("raw_data_1_9").Visible = False
End Sub
Try this. I've declared your variables properly and also assigned values to your array using Array() rather than Split() both are fine, but Array() is more flexible
Sub clear_sheets()
Dim sheetNames As Variant
Dim count As Integer
sheetNames = Array("AA", "BB", "CC")
For Count = 0 To UBound(Snames)
With Sheets(sheetNames(Count))
Range(.Range("A3"), .Range("C3").End(xlDown)).ClearContents
End With
Next
Sheets("MENU").Select
Optimise (False)
End Sub
Also, it's better to use ThisWorkbook.Sheets()rather than just Sheets() if your code refers to the same workbook you are writing your VBA in. If you don't do this then VBA will assume you are referring to the sheets in whichever workbook is active when you run the code - that's not usually a good thing.
Update
I've changed the code to delete what I think you might want deleted?
Use:
Snames = Split("AA", "BB", "CC")

Loop for repeating statement

I need to write a Loop to run the following lines until the third line finds the cell it is selecting to be empty.
I would normally include my code for the loop to be corrected / critiqued but after searching all morning I can't find an example of do while loop that doesn't count to keep moving.
Can someone point me in the right direction with a link or two?
Sheets("Sheet1").Select
Selection.Offset(0, 3).Select
Selection.Offset(1, 0).Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection(1, 3)).Select
Selection.Copy
Sheets("Output").Select
Selection.End(xlDown).Select
Selection.Offset(1, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Include Fund name
Sheets("Sheet1").Select
Selection.End(xlUp).Select
Selection.Copy
Sheets("Output").Select
Range("B2").Select
Selection.End(xlDown).Select
Selection.Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.Offset(0, 1).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Offset(0, -1).Select
Selection.FillDown
I can't find an example of do while loop that doesn't count to keep moving.
You didn't look very hard, then. All Do or While loops should have a terminator, or an Exit statement, otherwise they will crash the application in an infinite loop.
Try:
Do Until Sheets("Sheet1").Selection.Offset(1, 0).Value = vbNullString
'// YOUR CODE HERE //
Loop
Or:
Do
If Sheets("Sheet1").Selection.Offset(1, 0).Value = vbNullString Then Exit Do
'// YOUR CODE HERE //
Loop