Selecting sheet name

AndreMichielsen

New Member
Joined
May 5, 2021
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have a problem with selecting the right sheet with VBA.

I have a workbook with a form made in sheet 1
I have a workbook with all the months of the Year, i.e. January, February and so on.

I made a form in which one can fill some data and in one specific cell the date you want something done.
After completing the formdata, with one push on a button I open another workbook, save the data and close it again.
But in the macro I made I have to mention the specific name of the month to save the data.
All I want is that the month name of the cell in the form is compared to the right sheet name in the other workbook and so save the data in the right sheet, before closing the workbook again.
After that i clear the form and can start fill it again with new data.

What i can't find is how to select the right sheet according to the month name in the cell on the form.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Welcome to the board.

If your form has an Excel date in say cell D5, try something like:

Code:
Sheets(Format(Sheets("Form Sheet Name").Range("D5").Value,"mmmm")).Select

Since Sheets("Form sheet Name").Range("D5") has an Excel date, using the Format function will convert it into the months that your sheets are named.
 
Last edited:
Upvote 0
Sorry for my late reaction.
I put in the line that you proposed but I it doesn't work.
So I copied a part of my VBA code.
I work with a workbook 1 with in it a form and thus the date cell in F6
After finishing the form I want to save the information in an other workbook on the sheet with the according monthname
Now I change the macro every month as you can see in the formula but i would like the macro to choose the right month.
Hope you can help me.

André


'Workbook 1 contains the form in which the date cell

Dim DeliveryDate As Date
DeliveryDate = Range("F6")

Workbooks.Open "C:\Users\OneDrive\BOL sheets\Logistics 2021 Workbook.xlsx"

WorkSheets(Format(Sheets("Form sheets Name").Range("F6").Value,"mmmm").Select

Worksheets("May").Select
Worksheets("May").Range("A1").Select

If Worksheets("May").Range("A1").Offset(1, 0) <> "" Then
Worksheets("May").Range("A1").End(xlDown).Select
End If

ActiveCell.Offset(1, 0).Select
ActiveCell.Value = DeliveryDate
'etc....
 
Upvote 0
OK, "Form sheets Name" was intended to be the name of the actual sheet in the source file.

But, more importantly, I think you'll find it much easier to switch between the two files if you assign variables to them.

For example:

Code:
Sub CopyToOtherWorkbook()
Dim shtSourceSht As Worksheet
Dim wbkDestination As Workbook


Set shtSourceSht = ActiveSheet
Set wbkDestination = Workbooks.Open("C:\Users\OneDrive\BOL sheets\Logistics 2021 Workbook.xlsx")

With wbkDestination.Sheets(Format(shtSourceSht.Range("F6").Value, "mmmm"))

'do some stuff

End With


End Sub

Here, you'll note that I replaced the "Form sheets Name" idea with a reference to the active sheet instead. That part is different, but the idea of envoking Format(reference cell, "mmmm") is the crux of the suggestion anyway. That part is the same.
 
Upvote 0
Thank you again but the macro always stops at the line "With wbkDestination.Sheets( .. " )and it shows the remark ;"This property or method is not supported by this object"
I tried everything but I have no idea what to do next.
 
Upvote 0
When you get the debug error, what does
Code:
 ?shtSourceSht.Range("F6").Value
return in the immediate window of VBE?
 
Upvote 0
Dear members

I have posted this problem before on this site but due to circumstances I was not able to react on time to questions from people who would dive into my problem.

I have to workbooks,
Workbook 1 is named BOL and contains 2 worksheets.
Workbook 2 is named Logistics and contains 12 worksheets, one for every month

In Workbook 1 the first worksheet is named Client list and that has all kind of address information.
The second worksheet is called Lading and is made as a form that you fill with all kind of information and the address information that we retrieve from client list. This worksheet has also a date field that we fill with a certain date.
After we finished the form we push a button and with that we save this form as pdf, as excel and it opens Workbook 2 (Logistics) and opens a Sheet and save all the data from this form on the first empty row.
Then it closes this Workbook 2.

What I can’t make is that, depending of the month name in the form of the sheet Lading, Workbook 2 opens on the worksheet with the right month name and save the information there. So if on the Lading sheet the month is May, on Workbook 2 the worksheet with the month name May is opened and the info saved there on the first empty row
I Hope somebody can help me,

Greetings from the Netherlands.

At this moment I have this formula made in VBA:

'Open existing Workbook Logistics and then
'Writing Bol info to Workbook and close it again

Dim BolNumber As String, DeliveryDate As Date, Time As String, Commodity As String, Consignee As String, ReleaseNumber As String, AccountNumber As Integer, AccountName As String, ShipfromName As String, ShipfromAddress As String, ShipfromTown As String, ShipfromPostalCode As String, Unloaddate As Date, ShiptoName As String, ShiptoRelease As String, ShiptoAddress As String, ShiptoTown As String, ShiptoPostalCode As String, CarrierName As String, CarrierAddress As String, CarrierTown As String, CarrierPostalCode As String, LastCommodityTransported As String, Remarks As String, Shippingnotes As String

BolNumber = Range("K4")
DeliveryDate = Range("F6")
Time = Range("J29")
ShipfromName = Range("B15")
Commodity = Range("F4")
CarrierName = Range("B33")
Consignee = Range("B26")
ReleaseNumber = Range("F29")
Unloaddate = Range("F6")
Shippingnotes = Range("B38")

Workbooks.Open "C:\Users\DCI\OneDrive\ Logistics Workbook.xlsx"
Worksheets("July").Select
Worksheets("July").Range("A1").Select
If Worksheets("July").Range("A1").Offset(1, 0) <> "" Then
Worksheets("July").Range("A1").End(xlDown).Select
End If

ActiveCell.Offset(1, 0).Select
ActiveCell.Value = DeliveryDate
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Time
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = BolNumber
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = ShipfromName
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Commodity
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = CarrierName
ActiveCell.Offset(0, 3).Select
ActiveCell.Value = Consignee
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = ReleaseNumber
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = DeliveryDate
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Shippingnotes

ActiveWorkbook.Close Savechanges:=True
 
Upvote 0
It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your Client List and Lading sheets and also of one of the month sheets from workbook 2. Alternately, you could upload a copy of your two files to a free site such as www.box.com or www.dropbox.com. Once you do that, mark each file for 'Sharing' and you will be given a link to each file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0
VDB Bill of Lading 01-07-21 used CA.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAE
1IdShort NameNameCityStateCountryOrigin/DestinationInactiveAddress Line 1Address Line 2Zip/Postal CodeCurrencyTrader/SalesrepContact NamePhoneExtFax NoToll FreeMobile/CellEmailWeb AddressGST/VAT/ABN NoA/R TermsDescriptionA/P TermsDescriptionLast ChangedChanged ByGST Exemption NoPST/HST Exemption NoTax 3 Exemption No
21000MurrayKKevin MurrayWaltonONCanadaN82009 Manley Line, RR#4Huron EastN0K 1Z0CNDKevin Murray519-345-2199519-301-1054kmurray@tcc.on.ca9-12-2020 12:38NADINEExempt
31001Belmont FaBelmont Farm Supply IncBelmontONCanadaN14000 Belmont Road, P.O.Box 310N0L 1B0CNDRon Van Der BurgtBelmont Farm Supply Inc519-644-1650519-644-1795519-281-9541shosford@belmontfarmsupply.com9-12-2020 12:39NADINEExempt
41002FroudJJohn FroudSt. MarysONCanadaN5604 Line 12, RR#1N4X 1C4CNDJohn Froud519-671-1188bottlebush@quadro.net9-12-2020 12:39NADINEExempt
51003VanNynPP & M Van Nynatten IncSebringvilleONCanadaN4901 Line 39N0K 1X0CNDP & M Van Nynatten Inc519-393-5731petevn@hotmail.com15-7-2020 12:57ELLENExempt
61004SteunebrinLars C SteunebrinkKirktonONCanadaN42540 Huron StreetN0K 1K0CNDLars C Steunebrink519-274-4370larssteunebrink@hotmail.com7-12-2020 11:22NADINEExempt
71005LindnerBBradilee Farms Ltd c/o Brad LindnerSebringvilleONCanadaN4633 Road 130, RR#1N0K 1X0CNDBradilee Farms Ltd c/o Brad Lindner519-393-5728519-395-5728519-276-1116Bradileefarms@yahoo.ca9-12-2020 12:40NADINEExempt
81006DeWeteringDeWetering Disposal Ltd.SebringvilleONCanadaN4618 Road 145, RR#1N0K 1X0CNDDeWetering Disposal Ltd.519-393-5250deweteringdisposal@gmail.com9-12-2020 12:41NADINEExempt
91007QT Info SyQT Info Systems, IncChicagoILUnited StatesN141 West Jackson BlvdSuite 1220 A60604CNDQT Info Systems, Inc21-7-2020 12:50ELLEN
101008Tire CraftTire Craft Honeywood Tire LtdStratfordONCanadaN42 Dunlop PlaceRR#3N5A 6S4CNDTire Craft Honeywood Tire Ltd519-273-3111519-273-312322-10-2020 13:28BKAExempt
Clientlist_Feb_25_2021


VDB Bill of Lading 01-07-21 used CA.xlsm
F
6donderdag, apr 29, 2021
Bill of Lading


Logistics Workbook 2021 AM.xlsx
ABCDEFGHIJKL
1DateTimeBOL #Ship from NameCommodityFreight Carrier NameFreight RateContract# ConsigneePO# / Release #Unload DateShipping Notes
226-03-202169V.D.B. Grains LTDCorn0026-03-2021
326-03-20211169V.D.B. Grains LTDCorn0026-3-2021
426-03-202170V.D.B. Grains LTDCorn0026-03-2021
527-03-202125 mar71V.D.B. Grains LTDCornLars C SteunebrinkJohn Froudfff27-03-2021kkkk
6
March
 
Upvote 0
Do these ranges refer to the Lading sheet:
VBA Code:
BolNumber = Range("K4")
DeliveryDate = Range("F6")
Time = Range("J29")
ShipfromName = Range("B15")
Commodity = Range("F4")
CarrierName = Range("B33")
Consignee = Range("B26")
ReleaseNumber = Range("F29")
Unloaddate = Range("F6")
Shippingnotes = Range("B38")
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,749
Members
449,050
Latest member
excelknuckles

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