Consulting

Results 1 to 10 of 10

Thread: Error's want to help

  1. #1
    VBAX Contributor
    Joined
    Jun 2008
    Posts
    169
    Location

    Error's want to help

    Daer Experts

    The intents of the code is wanted when getting external data to paste in my object WS Col A” and if “COL A have values then automatically to paste in the Col “B …Etc to across from left to right column , base the header of Date / Month to go.

    But it can’t be work :
    Can u help to modify or learn me about what’s was it wrong. Thanks very much



    [VBA]
    Sub test()
    Dim home As Worksheet
    Dim Filename As String, myDir As String, fn As String
    Dim COLCOUNT As Long
    COLCOUNT = 0
    Set home = ThisWorkbook.ActiveSheet
    COLCOUNT = 1 + 1
    With Application.FileDialog(msoFileDialogOpen)
    .AllowMultiSelect = False
    If .Show = -1 Then
    Filename = .SelectedItems(1)
    myDir = Left$(Filename, InStrRev(Filename, "\"))
    fn = Mid$(Filename, InStrRev(Filename, "\") + 1)
    With home.Cells(COLCOUNT + 1).End(xlUp)(1).Resize(1)
    .Formula = "='" & myDir & "[" & fn & "]Sheet1'!K6"
    .Value = .Value
    COLCOUNT = COLCOUNT + 1
    End With
    End If
    End With
    End Sub
    [/VBA]

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You are selecting the same cell for pasted values. Your code should be something like
    [VBA]
    With home.Cells(1, Columns.Count).End(xlToLeft).Offset(, 1)
    .Select 'for debugging
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Contributor
    Joined
    Jun 2008
    Posts
    169
    Location
    Dear Mdmackillop

    Very thanks your help,
    additional one if I wanto to change the formulas to copy form the worksheets K2 to K13 how's it change?

    Thanks
    Very much

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]For k = 2 To 13
    With home.Cells(1, Columns.Count).End(xlToLeft).Offset(, 1)
    .Formula = "='" & myDir & "[" & fn & "]Sheet1'!K" & k
    .Value = .Value
    COLCOUNT = COLCOUNT + 1
    End With
    Next[/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Contributor
    Joined
    Jun 2008
    Posts
    169
    Location
    Dear Mdmackillop


    The code seems copy from K to left counted....

    might I message not clear,
    I means to want copy form file Range (K2 to K13) then paste in my objects sheets...

    would you mind help again, thanks very much

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I'm not clear where data is to be pasted. Can you show this on a sample workbook and post it?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    VBAX Contributor
    Joined
    Jun 2008
    Posts
    169
    Location
    Thanks Your help


    Format same as attached & which file is by daily.

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]Sub testing()
    Dim home As Worksheet
    Dim FNname As String
    Dim Wb As Workbook
    Dim Tgt As Range

    Set home = ActiveSheet

    With Application.FileDialog(msoFileDialogOpen)
    .AllowMultiSelect = False
    If .Show = -1 Then
    'Get target for paste
    Set Tgt = home.Cells(2, Columns.Count).End(xlToLeft).Offset(, 1)
    'Open Source file
    FName = Application.GetOpenFilename("Excel Files (*.xls), *.xls")
    If FName <> False Then
    Set Wb = Workbooks.Open(FName)
    'Copy and PasteSpecial values
    Wb.Worksheets("MAN_SUM").Range("H13:H16").Copy
    Tgt.PasteSpecial xlPasteValues
    'Close Source wihout saving
    Wb.Close False
    End If
    End If
    End With
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    VBAX Contributor
    Joined
    Jun 2008
    Posts
    169
    Location
    Dear Mdmackillop

    Your code is perfectly.

    Thanks very much.

  10. #10
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Perfect example of why you should post an example workbook. It would have saved Malcolm quite a bit of time trying to figure out what you were trying to do.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •