How to select different tables (Table1, Table2, Table3... using VBA

Chiwidan

New Member
Joined
Apr 19, 2020
Messages
15
Office Version
  1. 2010
Platform
  1. Windows
Hi guys,

I hope you are having a good week so far. Greetings from New Zealand.

I am stuck but I will say this will be quite a basic question:

In a worksheet called "calculations" I have different 10 tables (From Table2 to Table11)

I am trying to pull the information from Table"i+1" but I am unsure how to code it.

Below is what I have but it gets stuck in the first line (on yellow)

VBA Code:
Sub Invoice_Making()


Dim shMacros As Worksheet, shCalculations As Worksheet, shInvTemplate As Worksheet
Set shMacros = Worksheets("Macros")
Set shCalculations = Worksheets("Calculations")
Set shInvTemplate = Worksheets("Invoice Template")

'Inserts new sheets, and names them a name according to form
 
Sheets("Macros").Select

Dim sheet_count As Integer

sheet_count = Range("E2")

Dim sheet_name As String
Dim i As Integer



For i = 1 To sheet_count


'copy NHI from Calculations to Invoice Template


    [COLOR=rgb(247, 218, 100)]shCalculations.Range("Table" & "(i+1)[NHI]").Copy shInvTemplate.Range("X3")[/COLOR]
 
    shCalculations.Range("Table&i+1[NHI2]").Copy shInvTemplate.Range("X19")
 
    shCalculations.Range("Table&i+1[NHI3]").Copy shInvTemplate.Range("X35")
shCalculations.Range("Table&i+1[NHI4]").Copy shInvTemplate.Range("X51")
 
I am slowly getting there... I have the InvTemplate worksheet where the previous part of the Macro will put the information. I also have a template worksheet (shInvTemplate)

My next steps are:

1 To automatically create a worksheet which name will change every time:


VBA Code:
'Creates Invoice Worksheet

    sheet_name = shMacros.Range("A24:A33").Cells(i, 1).Value
    Sheets.Add.Name = sheet_name


2 To copy the information of my Invoice Sample

3 To paste in the newly created worksheet...

But I got stuck... I asked in the forum:

how to refer a newly created worksheet?


I got the gust feeling I am missing something really simple...

Dan
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.
You need to continue in your new thread.
 
Upvote 0

Forum statistics

Threads
1,216,083
Messages
6,128,718
Members
449,465
Latest member
TAKLAM

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