ComboBox1 Value is a Sheet Name, how to open that sheet? Also go to value in Combobox2 &.......

southcraven

New Member
Joined
Dec 1, 2014
Messages
7
Hi,

First thanks to all most of my code is taken from the site, & I am not experienced in VBA yet.

I have a database in Excel (Access not available to all the users). The database represents different land survey control points, at different locations. The format of each sheet (except a summary sheet called Control) is identical, each sheet is a different location, sheet name is the location. Each row has different values and includes 3 images, column "A" is the control point name, and so on, Row 1 being the field names. The VBA code should when a User opens the workbook, display a Form, in ComboBox1 the users selects a location, which automatically fills ComboBox2. So far I have the form, and have coded the combo boxes to fill correctly. It is not elegant code but it works, I would prefer to have a dynamic code rather then Case Select to fill ComboBox2.

On the form is a cmd button which is hard coded to a particular sheet and selects using autofilter the control point selected in Combobox2. Again would like the work sheet to be selected dynamically based on the Combobox1 value. Even though the row with the correct data is selected, the User cannot see it and must find it themselves, again would prefer that the row is not filter just highlighted.

Below is the UserForm code

Code:
Private Sub ComboBox1_Change()


Me.ComboBox2 = ""


Select Case Me.ComboBox1
    Case "A_Island"
        Me.ComboBox2.RowSource = "A_Island"
    Case "D_Island"
        Me.ComboBox2.RowSource = "D_Island"
    Case "EPC2_"
        Me.ComboBox2.RowSource = "EPC2_"
    Case "EPC3_"
        Me.ComboBox2.RowSource = "EPC3_"
    Case "EPC4_"
        Me.ComboBox2.RowSource = "EPC4_"
    Case "OPF"
        Me.ComboBox2.RowSource = "OPF"
    Case "EWRP"
        Me.ComboBox2.RowSource = "EWRP"
    Case "Bautino"
        Me.ComboBox2.RowSource = "Bautino"
    Case "Trunkline"
        Me.ComboBox2.RowSource = "Trunkline"
    
    Case Else
        'do nothing
End Select
End Sub




Private Sub ComboBox2_Change()


End Sub


Private Sub CommandButton1_Click()


 Application.ScreenUpdating = False
    With Sheets = ComboBox1.Value.UsedRange 'worksheet with your data
        .AutoFilter 'Clear previous filter if any
        
        
        If ComboBox2.ListIndex > -1 Then .AutoFilter 1, ComboBox2.Value
        
        
    
    End With
    Application.ScreenUpdating = True






End Sub


Private Sub CommandButton2_Click()
Unload Me
End Sub



Finally once the user has confirmed that the data contained in the particular row is correct I want to copy and paste to a word template. So far the code I have appears to work but I really need it to be dynamic, i.e. instead of using cells as shown below I want the use the row selected in the UserForm automatically, especially the images.


Code:
Sub CommandPrint1()
'
' CommandPrint_Click Macro
' Opens Word Template pastes BM data saves as new file name
'
UserForm1.Show


Dim WDApp As Word.Application   'opens word in background
    Dim WDDoc As Word.Document
 
    Set WDApp = New Word.Application
 
    With WDApp
         Set WDDoc = .Documents.Add(Template:="Survey Station Description 3.dotm")
        .Visible = True     'line above opens the station description template this line makes it visible
        .Selection.GoTo what:=wdGoToBookmark, Name:="Name"
        .Selection.TypeText Text:=Range("A6").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="Location"
        .Selection.TypeText Text:=Range("B6").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="Lat4326"
        .Selection.TypeText Text:=Range("C6").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="Long4326"
        .Selection.TypeText Text:=Range("D6").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="Lat1303v4284"
        .Selection.TypeText Text:=Range("E6").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="Long1303v4284"
        .Selection.TypeText Text:=Range("F6").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="E1303v28409"
        .Selection.TypeText Text:=Range("G6").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="N1303v28409"
        .Selection.TypeText Text:=Range("H6").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="Lat15865v4284"
        .Selection.TypeText Text:=Range("I6").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="Long15865v4284"
        .Selection.TypeText Text:=Range("J6").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="E15865v28409"
        .Selection.TypeText Text:=Range("K6").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="N15865v28409"
        .Selection.TypeText Text:=Range("L6").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="Elevation"
        .Selection.TypeText Text:=Range("M6").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="ScaleFactor"
        .Selection.TypeText Text:=Range("N6").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="LocalGridE"
        .Selection.TypeText Text:=Range("O6").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="LocalGridN"
        .Selection.TypeText Text:=Range("P6").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="txtPoint"
        .Selection.TypeText Text:=Range("Q6").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="txtNotes"
        .Selection.TypeText Text:=Range("R6").Value
        
        'code above copies all control point information from the excel sheet on row 6 and pastes it into the template but opens it in a new word document
        
        'code below copies images and paste into the new word document so far only one image is used, this is test code
        
        Worksheets("Sheet1").Shapes("Picture 6").Copy
        .Selection.GoTo what:=wdGoToBookmark, Name:="Map"
        .Selection.PasteSpecial Link:=False, DisplayAsIcon:=False, _
            DataType:=wdPasteMetafilePicture ', Placement:=wdFloatOverText
        
        
    End With
   
errorHandler:
Set WDApp = Nothing
Set myDoc = Nothing




End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
This userform code is untested.

Code:
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] ComboBox1_Change()
    
    Me.ComboBox2.Value = ""
    
    [COLOR=darkblue]If[/COLOR] ComboBox1.ListIndex > -1 [COLOR=darkblue]Then[/COLOR]    [COLOR=green]'Test if there is a selection from the list[/COLOR]
        Me.ComboBox2.RowSource = ComboBox1.Value
        Sheets(ComboBox1.Value).Select  [COLOR=green]'Select sheet[/COLOR]
    [COLOR=darkblue]Else[/COLOR]
        Me.ComboBox2.RowSource = ""
        Sheets("Control").Select        [COLOR=green]'Select "Control" sheet[/COLOR]
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
    
    
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] ComboBox2_Change()
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
    
    
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] CommandButton1_Click()
    [COLOR=darkblue]Dim[/COLOR] v [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Variant[/COLOR]
    [COLOR=darkblue]If[/COLOR] ComboBox2.ListIndex > -1 [COLOR=darkblue]Then[/COLOR]
        v = Application.Match(ComboBox2.Value, Range("A:A"), 0)
        [COLOR=darkblue]If[/COLOR] IsNumeric(v) [COLOR=darkblue]Then[/COLOR]
            Rows(v).Select
        [COLOR=darkblue]Else[/COLOR]
            MsgBox "Cannot match the selected Control Point. ", vbExclamation, "No Match Found"
        [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    [COLOR=darkblue]Else[/COLOR]
        MsgBox "1st select a 'Control Point'. ", vbExclamation, "Missing Control Point"
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
    
    
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] CommandButton2_Click()
    Unload Me
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]


This should copy values from the selected row (untested).
I didn't understand how you wanted to modify the image part of the code.

Code:
[COLOR=darkblue]Sub[/COLOR] CommandPrint1()
[COLOR=green]'[/COLOR]
[COLOR=green]' CommandPrint_Click Macro[/COLOR]
[COLOR=green]' Opens Word Template pastes BM data saves as new file name[/COLOR]
[COLOR=green]'[/COLOR]

[B]    [COLOR=darkblue]Dim[/COLOR] rngCProw [COLOR=darkblue]As[/COLOR] Range
    
    [COLOR=darkblue]Set[/COLOR] rngCProw = ActiveCell.EntireRow [COLOR=green]'selected row as range variable[/COLOR]
    rngCProw.Select [COLOR=green]'reselect row if user selected one cell[/COLOR][/B]
    
    UserForm1.Show

    [COLOR=darkblue]Dim[/COLOR] WDApp [COLOR=darkblue]As[/COLOR] Word.Application   [COLOR=green]'opens word in background[/COLOR]
    [COLOR=darkblue]Dim[/COLOR] WDDoc [COLOR=darkblue]As[/COLOR] Word.Document
 
    [COLOR=darkblue]Set[/COLOR] WDApp = [COLOR=darkblue]New[/COLOR] Word.Application
 
    [COLOR=darkblue]With[/COLOR] WDApp
         [COLOR=darkblue]Set[/COLOR] WDDoc = .Documents.Add(Template:="Survey Station Description 3.dotm")
        .Visible = [COLOR=darkblue]True[/COLOR]     [COLOR=green]'line above opens the station description template this line makes it visible[/COLOR]
        .Selection.GoTo what:=wdGoToBookmark, Name:="Name"
        .Selection.TypeText Text:=[B]rngCProw.Range("A1").Value[/B]
        .Selection.GoTo what:=wdGoToBookmark, Name:="Location"
        .Selection.TypeText Text:=rngCProw.Range("B1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="Lat4326"
        .Selection.TypeText Text:=rngCProw.Range("C1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="Long4326"
        .Selection.TypeText Text:=rngCProw.Range("D1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="Lat1303v4284"
        .Selection.TypeText Text:=rngCProw.Range("E1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="Long1303v4284"
        .Selection.TypeText Text:=rngCProw.Range("F1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="E1303v28409"
        .Selection.TypeText Text:=rngCProw.Range("G1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="N1303v28409"
        .Selection.TypeText Text:=rngCProw.Range("H1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="Lat15865v4284"
        .Selection.TypeText Text:=rngCProw.Range("I1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="Long15865v4284"
        .Selection.TypeText Text:=rngCProw.Range("J1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="E15865v28409"
        .Selection.TypeText Text:=rngCProw.Range("K1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="N15865v28409"
        .Selection.TypeText Text:=rngCProw.Range("L1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="Elevation"
        .Selection.TypeText Text:=rngCProw.Range("M1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="ScaleFactor"
        .Selection.TypeText Text:=rngCProw.Range("N1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="LocalGridE"
        .Selection.TypeText Text:=rngCProw.Range("O1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="LocalGridN"
        .Selection.TypeText Text:=rngCProw.Range("P1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="txtPoint"
        .Selection.TypeText Text:=rngCProw.Range("Q1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="txtNotes"
        .Selection.TypeText Text:=rngCProw.Range("R1").Value
        
        [COLOR=green]'code above copies all control point information from the excel sheet on row 6 and pastes it into the template but opens it in a new word document[/COLOR]
        
        [COLOR=green]'code below copies images and paste into the new word document so far only one image is used, this is test code[/COLOR]
        
[COLOR=green]'????[/COLOR]
[COLOR=green]'        Worksheets("Sheet1").Shapes("Picture 6").Copy[/COLOR]
[COLOR=green]'        .Selection.GoTo what:=wdGoToBookmark, Name:="Map"[/COLOR]
[COLOR=green]'        .Selection.PasteSpecial Link:=False, DisplayAsIcon:=False, _
'            DataType:=wdPasteMetafilePicture ', Placement:=wdFloatOverText[/COLOR]
        
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
   
errorHandler:
[COLOR=darkblue]Set[/COLOR] WDApp = [COLOR=darkblue]Nothing[/COLOR]
[COLOR=darkblue]Set[/COLOR] myDoc = [COLOR=darkblue]Nothing[/COLOR]
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
 
Upvote 0
Alpha Frog,

Many thanks for your reply.

1 - Private Sub ComboBox1_Change() code works fine. When the Control Point Selection form combo boxes are populated, & commandbutton click runs, the specified sheet opens & correct row on the sheet is highlighted, brilliant.


2 -For the
Sub CommandPrint1() - I placed another cmdbutton on sheet("CONTROL") to run the code. I do not receive errors but the word template is populated from the sheet("CONTROL"). As I assume it runs the following code, as a cell is selected in this sheet.
Set rngCProw = ActiveCell.EntireRow 'selected row as range variable
rngCProw.Select 'reselect row if user selected one cell

I deleted the cmdbutton in the Control sheet, now if I run the code from the VB using F5 it correctly copies and pastes the selected control point data in the form into the word template. Not sure how that works seeing how the .selection.......section is still A1, B1, C1, etc and not the rowsource selected from the form! Anyway I now ran the code by using a macro, there is still a small problem. When I open the excel sheet whatever cell was selected the last time the excel sheet was closed is sent to the word template not the one currently selected in the form and I need to close the form to get the code to fire. The next time I run the marco the correct data is sent to the word template. Would also prefer not to close the form, easier for the users.


There is one little bug, some of my control point names are numeric , i.e. "809" (no quotation marks), these will not work, I can add a letter prefix but would prefer not to, any suggestions?

Regards the pasting of images; columns "S", "T", & "U" contain jpg images that need pasting into the word document. the code Selection.TypeText Text:=rngCProw.Range("S1").Value does not work (for text?). But as an experiment I used the code you commented out BUT AGAIN the code is not dynamic even though it successfully pasted the image i.e. "Picture 6". How can I add code that will select the images to .Selection.GoTo what:=wdGoToBookmark, Name:="Map", .Selection.GoTo what:=wdGoToBookmark, Name:="Close", .Selection.GoTo what:=wdGoToBookmark, Name:="Location", the bookmarks are within the same word template.

If you want the file how can I post it? Or dropbox maybe?
 
Upvote 0
You're welcome.

Not sure how that works seeing how the .selection.......section is still A1, B1, C1, etc and not the rowsource selected from the form!
A1, B1...etc. are relative to the variable rngPCrow and not the worksheet. So rngPCrow was assigned as the highlighted row. So A1 in this reference...
rngCProw.Range("A1").Value
...is the first cell in rngPCrow.

When I open the excel sheet whatever cell was selected the last time the excel sheet was closed is sent to the word template not the one currently selected in the form and I need to close the form to get the code to fire. The next time I run the marco the correct data is sent to the word template. Would also prefer not to close the form, easier for the users.

When you first show the userform, use this to call it
UserForm1.Show vbModeless

That will allow the user to interact with the worksheet without having to close the userform.

Put a Print command button on the userform
Code:
[color=darkblue]Sub[/color] cmdPrint()
[color=green]'[/color]
[color=green]' cmdPrint_Click[/color]
[color=green]' Opens Word Template pastes BM data saves as new file name[/color]
[color=green]'[/color]
    
    [color=darkblue]Dim[/color] rngCProw [color=darkblue]As[/color] Range
    [color=darkblue]Dim[/color] Pic [color=darkblue]As[/color] Picture
    
    [color=darkblue]Set[/color] rngCProw = ActiveCell.EntireRow [color=green]'selected row as range variable[/color]
    rngCProw.Select [color=green]'reselect row if user selected one cell[/color]
    
[color=green]'    UserForm1.Show[/color]

    [color=darkblue]Dim[/color] WDApp [color=darkblue]As[/color] Word.Application   [color=green]'opens word in background[/color]
    [color=darkblue]Dim[/color] WDDoc [color=darkblue]As[/color] Word.Document

    [color=darkblue]Set[/color] WDApp = [color=darkblue]New[/color] Word.Application

    [color=darkblue]With[/color] WDApp
         [color=darkblue]Set[/color] WDDoc = .Documents.Add(Template:="Survey Station Description 3.dotm")
        .Visible = [color=darkblue]True[/color]     [color=green]'line above opens the station description template this line makes it visible[/color]
        .Selection.GoTo what:=wdGoToBookmark, Name:="Name"
        .Selection.TypeText Text:=rngCProw.Range("A1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="Location"
        .Selection.TypeText Text:=rngCProw.Range("B1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="Lat4326"
        .Selection.TypeText Text:=rngCProw.Range("C1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="Long4326"
        .Selection.TypeText Text:=rngCProw.Range("D1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="Lat1303v4284"
        .Selection.TypeText Text:=rngCProw.Range("E1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="Long1303v4284"
        .Selection.TypeText Text:=rngCProw.Range("F1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="E1303v28409"
        .Selection.TypeText Text:=rngCProw.Range("G1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="N1303v28409"
        .Selection.TypeText Text:=rngCProw.Range("H1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="Lat15865v4284"
        .Selection.TypeText Text:=rngCProw.Range("I1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="Long15865v4284"
        .Selection.TypeText Text:=rngCProw.Range("J1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="E15865v28409"
        .Selection.TypeText Text:=rngCProw.Range("K1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="N15865v28409"
        .Selection.TypeText Text:=rngCProw.Range("L1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="Elevation"
        .Selection.TypeText Text:=rngCProw.Range("M1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="ScaleFactor"
        .Selection.TypeText Text:=rngCProw.Range("N1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="LocalGridE"
        .Selection.TypeText Text:=rngCProw.Range("O1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="LocalGridN"
        .Selection.TypeText Text:=rngCProw.Range("P1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="txtPoint"
        .Selection.TypeText Text:=rngCProw.Range("Q1").Value
        .Selection.GoTo what:=wdGoToBookmark, Name:="txtNotes"
        .Selection.TypeText Text:=rngCProw.Range("R1").Value
        
        [color=green]'copies images in columns S,T,U from the matched row[/color]
        [color=darkblue]For[/color] [color=darkblue]Each[/color] Pic [color=darkblue]In[/color] ActiveSheet.Pictures
            [color=darkblue]If[/color] Pic.TopLeftCell.Address = rngCProw.Range("S1").Address [color=darkblue]Then[/color]
                Pic.Copy
                .Selection.GoTo what:=wdGoToBookmark, Name:="Map"
                .Selection.PasteSpecial Link:=False, DisplayAsIcon:=False, _
                     DataType:=wdPasteMetafilePicture [color=green]', Placement:=wdFloatOverText[/color]
            [color=darkblue]ElseIf[/color] Pic.TopLeftCell.Address = rngCProw.Range("T1").Address [color=darkblue]Then[/color]
                Pic.Copy
                .Selection.GoTo what:=wdGoToBookmark, Name:="???"                   [color=green]'<---Change the bookmark Name to suit[/color]
                .Selection.PasteSpecial Link:=False, DisplayAsIcon:=False, _
                     DataType:=wdPasteMetafilePicture [color=green]', Placement:=wdFloatOverText[/color]
            [color=darkblue]ElseIf[/color] Pic.TopLeftCell.Address = rngCProw.Range("U1").Address [color=darkblue]Then[/color]
                Pic.Copy
                .Selection.GoTo what:=wdGoToBookmark, Name:="???"                   [color=green]'<---Change the bookmark Name to suit[/color]
                .Selection.PasteSpecial Link:=False, DisplayAsIcon:=False, _
                     DataType:=wdPasteMetafilePicture [color=green]', Placement:=wdFloatOverText[/color]
            [color=darkblue]End[/color] [color=darkblue]If[/color]
        [color=darkblue]Next[/color] Pic
        
    [color=darkblue]End[/color] [color=darkblue]With[/color]
    
    [color=darkblue]Set[/color] WDApp = [color=darkblue]Nothing[/color]
    [color=darkblue]Set[/color] myDoc = [color=darkblue]Nothing[/color]
    
[color=darkblue]End[/color] [color=darkblue]Sub[/color]


Regards the pasting of images; columns "S", "T", & "U" contain jpg images that need pasting into the word document.

See the print code above (not tested). You have to change the bookmarks for the pictures in columns T and U.


There is one little bug, some of my control point names are numeric , i.e. "809" (no quotation marks), these will not work, I can add a letter prefix but would prefer not to, any suggestions?
What exactly does "will not work" mean; Do you get an error or a message box; what happens?
 
Upvote 0
AlphaFrog,

Just got in the office, thanks for your reply. I will try your code for the pictures etc, as soon as I can. Meanwhile to answer your last question:

With a control point name which is only numeric (i.e. 801 or 903) selected in ComboBox2, the Commandbutton1 click event causes your MsgBox code to run No Match Found. Once I click OK to close the MsgBox and select an alphanumeric control point (i.e. A-125, H-4 ) the code executes OK.

Again thanks, especially taking the time to explain how the variable rngPCrow operates.

Whilst I find this and other forums really useful, I find that VBA is best explained on various YouTube videos, can you recommend any particularly good sites?

Thanks Nick
 
Upvote 0
AlphaFrog,

Sorry to report the code generates Error 438 Object doesn't support this property or method at line For Each Pic In ActiveSheet.Picture.Select

Nick
 
Upvote 0
AlphaFrog,

Sorry to report the code generates Error 438 Object doesn't support this property or method at line For Each Pic In ActiveSheet.Picture.Select

Nick
Delete the .Select
That's not from my code.
For Each Pic In ActiveSheet.Picture.Select

It should be..
For Each Pic In ActiveSheet.Pictures
 
Last edited:
Upvote 0
With a control point name which is only numeric (i.e. 801 or 903) selected in ComboBox2, the Commandbutton1 click event causes your MsgBox code to run No Match Found. Once I click OK to close the MsgBox and select an alphanumeric control point (i.e. A-125, H-4 ) the code executes OK.

What's happening is the selected value from Combox2 is always a text string regardless if it's a number (801) or Alpha-Numeric (A-125). So the Match function then uses that selected text from Combox2 to search column A.

The problem is your entries in column A are both Numeric values (801 which is not text) and and text. So the Match function searching for the text 801 will not match the numeric value 801.

A simple solution would be to enter your numeric values in column A with a preceding single quote ('801). The single quote is not displayed and the entry is treated as text.
 
Upvote 0
AlphaFrog,

Sorry I messed up, I was trying myself to find ways of correcting the error and I left the .select in the example I sent you by mistake

It should be..
For Each Pic In ActiveSheet.Pictures

It is this code which gives the Error 438.

Sorry for the confusion.

Nick
 
Upvote 0

Forum statistics

Threads
1,214,388
Messages
6,119,229
Members
448,879
Latest member
VanGirl

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