Run VBA on ActiveWorkbook

punnipah

Board Regular
Joined
Nov 3, 2021
Messages
134
Office Version
  1. 2019
Platform
  1. Windows
Hi,,

i want to run Code on workbook VBA but my flow not working.


-Set sh = ActiveWorkbook.Sheets("Sheet1") : i want to get workbook opendata



Sub test()

Set sh = ActiveWorkbook.Sheets("Sheet1")
Set wb = Workbooks.Add
Set r = sh.Range("A:A")
Set f = r.Find("Com.", , xlValues, xlWhole, , , True)
If Not f Is Nothing Then
cell = f.Address
Do
sh.Range(Sheet1.Cells(f.Row + 1, 1), Sheet1.Cells(f.Row + (f.End(xlDown).Row - f.Row), 30)).Copy wb.Sheets(1).Range("A" & Rows.Count).End(3)(2)

Set f = r.FindNext(f)
Loop While Not f Is Nothing And f.Address <> cell
End If
End Sub



1678863152828.png
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
This is the approach I use
VBA Code:
Set WbName = ThisWorkbook
Set WsName = WbName.Worksheets(MASTERNAME)
Set WbNewName = Workbook.Add
Set WsNewName = ActiveWorksheet 'Since the new workbook will be open and active
 
Upvote 0
Solution
This is the approach I use
VBA Code:
Set WbName = ThisWorkbook
Set WsName = WbName.Worksheets(MASTERNAME)
Set WbNewName = Workbook.Add
Set WsNewName = ActiveWorksheet 'Since the new workbook will be open and active
Thank you very much
 
Upvote 0

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

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