VBA Help

Shalabh

New Member
Joined
Aug 19, 2016
Messages
22
Hi,

I want to perform below mentioned action in each of the two sheets but could not succeed. Can you please help.

Cells(6, column1 + 1).Value = "Total1"
Cells(6, column1 + 2).Value = "Total2"
Cells(6, column1 + 3).Value = "Total3"
Cells(6, column1 + 4).Value = "Total4"
Cells(6, column1 + 5).Value = "Total5"
Cells(6, column1 + 6).Value = "Total6"
Cells(6, column1 + 7).Value = "Total7"
Cells(6, column1 + 8).Value = ""Total8"
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Try

Code:
Sub MM1()
Dim c As Integer
c = 1
Cells(6, c + 1).Value = "Total1"
Cells(6, c + 2).Value = "Total2"
Cells(6, c + 3).Value = "Total3"
Cells(6, c + 4).Value = "Total4"
Cells(6, c + 5).Value = "Total5"
Cells(6, c + 6).Value = "Total6"
Cells(6, c + 7).Value = "Total7"
Cells(6, c + 8).Value = "Total8"
End Sub
 
Upvote 0
Hi,

I want to perform below mentioned action in each of the two sheets but could not succeed. Can you please help.

Cells(6, column1 + 1).Value = "Total1"
Cells(6, column1 + 2).Value = "Total2"
Cells(6, column1 + 3).Value = "Total3"
Cells(6, column1 + 4).Value = "Total4"
Cells(6, column1 + 5).Value = "Total5"
Cells(6, column1 + 6).Value = "Total6"
Cells(6, column1 + 7).Value = "Total7"
Cells(6, column1 + 8).Value = ""Total8"

In each of what two sheets?
 
Upvote 0
Hi Rick & Michael,

Thanks for your quick revert. May be I have not explained my query fully. I need to execute above mentioned code in each of the 2 sheets (out of 5 sheets in one workbook) simultaneously.
 
Upvote 0
Sheet names are - Companies, Countries
These two lines of code should do all the assignments you asked for...
Code:
[table="width: 500"]
[tr]
	[td]  Sheets("Companies").Cells(6, column1 + 1).Resize(, 8) = Array("Total1", "Total2", "Total3", "Total4", "Total5", "Total6", "Total7", "Total8")
  Sheets("Countries").Cells(6, column1 + 1).Resize(, 8) = Array("Total1", "Total2", "Total3", "Total4", "Total5", "Total6", "Total7", "Total8")[/td]
[/tr]
[/table]
 
Upvote 0
Hi Rik,

Thanks a lot. It solved my problem.

Now, let me go a step further. I have 10 lines of code which has to be repeated for both sheets - Companies and countries, is there a way to do it.

Thanks in advance.

Regards
Shalabh
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,307
Members
452,633
Latest member
DougMo

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