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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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,215,430
Messages
6,124,851
Members
449,194
Latest member
HellScout

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