VBA help with adding 2 columns

Gorandulac32

New Member
Joined
Jan 9, 2020
Messages
18
Office Version
  1. 2016
Platform
  1. Windows
Hi - i am a VBA beginner and I wondering how to add 2 cells (say B1 and C1) and have the results in A1. I want to do this for every sheet in my workbook and for every cell in column B and C.

Essentially B1+C1 in A1, B2+C2 in A2 and so on. I want the formula to drag down to the last row of data for each sheet.

thanks
 
Hi thanks for that..

I however get an error Run-time error ‘9’: Subscript out of range for the underlined/bolded/italicized below.

—————————————————————-

Sub MergeWorkbooks()

Dim FolderPath As String
Dim File As String
Dim i As Long


FolderPath = inputBox("C:\Users\Goran\2021")

File = Dir(FolderPath)

Do While File <> ""

Workbooks.Open FolderPath & File
ActiveWorkbook.Worksheets(1).Copy _
after:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count)
ActiveSheet.Name = Replace(File, ".xlsx", "")
Workbooks(File).Close

File = Dir()

Loop

For i = 1 To 12

Worksheets(MonthName(i, True)).Move after:=Worksheets(Worksheets.Count)

Next


End Sub

Loop
 
Upvote 0

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hi thanks for that..

I however get an error Run-time error ‘9’: Subscript out of range for the underlined/bolded/italicized below.

—————————————————————-

Sub MergeWorkbooks()

Dim FolderPath As String
Dim File As String
Dim i As Long


FolderPath = inputBox("C:\Users\Goran\2021")

File = Dir(FolderPath)

Do While File <> ""

Workbooks.Open FolderPath & File
ActiveWorkbook.Worksheets(1).Copy _
after:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count)
ActiveSheet.Name = Replace(File, ".xlsx", "")
Workbooks(File).Close

File = Dir()

Loop

For i = 1 To 12

Worksheets(MonthName(i, True)).Move after:=Worksheets(Worksheets.Count)

Next


End Sub

Loop
I am not sure how this pertains to any of the questions that were asked in this thread.
This appears to be a totally new and unrelated question.

Even if it is one the same project, all totally new questions should be posted to their own threads.
And you will probably need to provide more details, like what the name of your current sheets are.
 
Upvote 0
So the below code works to go into a file path C:\Users\Goran\2021\06 and takes all the files from that file path and combines them into 1 file and the contents of each file are a separate tab. For example 0601file, 0602file from the folder get created as a tab on the master file. The question is how do i dynamically account for the month change. The code I have below works, but i would need to change the date manually each time and then run the macro. Let me know if I should start a new post elsewhere. Thanks for you help thus far.



Sub MergeWorkbooks()

Dim FolderPath As String
Dim File As String
Dim i As Long


FolderPath = "C:\Users\Goran\2021\06

File = Dir(FolderPath)

Do While File <> ""

Workbooks.Open FolderPath & File
ActiveWorkbook.Worksheets(1).Copy _
after:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count)
ActiveSheet.Name = Replace(File, ".xlsx", "")
Workbooks(File).Close

File = Dir()

Loop

For i = 1 To 12

Worksheets(MonthName(i, True)).Move after:=Worksheets(Worksheets.Count)

Next


End Sub
 
Upvote 0
Yes, as I mentioned, since it is a new question, it should be posted to a new thread.

You do not want to keep adding new questions to existing threads. Most people won't see those, and if the people who are involved in the existing thread are unable or unavailable to assist, your chances of getting help are reduced greatly. As such, it isi generally recommended to post all brand new questions to new threads.
 
Upvote 0
For this code:

Dim dte As Date
dte = DateValue(Left(ActiveSheet.Name, 2) & "/" & Mid(ActiveSheet.Name, 3, 2))
Range("A1:A100") = dte

how could the range be the last row of tab and also how could i get it to loop through each tab and not just the active tab?

Thanks
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,716
Members
449,093
Latest member
Mnur

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