Code moves worksheets columns to the left thus not showing column A

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,752
Office Version
  1. 2007
Platform
  1. Windows
Hi,
I use the code below but i see that column A is off the page.
My code searches for a value in column B
It does that fine but how do i stop column A beeing out of sight ?

Thanks

Code:
Private Sub PurchasedKey_Click()
  Dim sPath As String
  Dim strFileName As String
  Dim sh As Worksheet
  Dim wb As Workbook
 
  With ActiveSheet
    If .Range("Q1") = "" Then
      MsgBox "NO CODE SHOWN TO GENERATE PDF", vbCritical, "NO CODE ON SHEET TO CREATE PDF"
      Exit Sub
    End If
    If .Range("N1") = "M" Then
    
    strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DISCO II CODE\DISCO II PDF\" & .Range("B3").Value & " (SLS).pdf"
    .Range("A1:K23").ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
    Else

    strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DISCO II CODE\DISCO II PDF\" & .Range("B3").Value & ".pdf"
    .Range("A1:K23").ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
    End If
    
    With ActiveSheet
    'ActiveWindow.SelectedSheets.PrintOut copies:=1
    Unload PrinterForm
    
    .Range("B3").Select
    Application.ScreenUpdating = False
    Dim C As Range
    Dim ans As String
    Dim Lastrow As Long
        ans = ActiveCell.Value
        Set wb = Application.Workbooks.Open("C:\Users\Ian\Desktop\REMOTES ETC\DR\DR.xlsm")
        Lastrow = Sheets("POSTAGE").Cells(Rows.Count, "B").End(xlUp).Row
    For Each C In Sheets("POSTAGE").Range("B1:B" & Lastrow)
        If C.Value = ans Then Application.Goto Reference:=wb.Sheets("POSTAGE").Range(C.Address): Exit For
    Next

 End With
 End With
          
          Application.Run ("'" & wb.Name & "'!openForm")
          Application.ScreenUpdating = True
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Cannot test due to the lack of relevant files, but try changing the For ... Next loop near the bottom of the code to this

VBA Code:
For Each C In Sheets("POSTAGE").Range("B1:B" & Lastrow)
  If C.Value = ans Then
    Application.Goto Reference:=wb.Sheets("POSTAGE").Range(C.Address)
    ActiveWindow.ScrollColumn = 1
    Exit For
Next
 
Upvote 0
I get Next withour For ?

Just a thought.
How about when this workbook is open have the code select column A then offset it by 1 so the column B is selected,obvioulsy not sure what to do there.
 
Upvote 0
I get Next withour For ?
My mistake (as I couldn't actually test)

Rich (BB code):
For Each C In Sheets("POSTAGE").Range("B1:B" & Lastrow)
  If C.Value = ans Then
    Application.Goto Reference:=wb.Sheets("POSTAGE").Range(C.Address)
    ActiveWindow.ScrollColumn = 1
    Exit For
  End If
Next
 
Upvote 0
Solution

Forum statistics

Threads
1,223,937
Messages
6,175,513
Members
452,650
Latest member
Tinfish

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