+ Reply to Thread
Results 1 to 10 of 10

Issues pasting in column B and making 2nd macro available

Hybrid View

sungsam Issues pasting in column B... 02-08-2008, 05:22 AM
davesexcel This workbook has quite a few... 02-08-2008, 08:33 AM
sungsam I've probably explained very... 02-08-2008, 09:20 AM
davesexcel I understand that would be... 02-09-2008, 11:41 AM
sungsam The macro brings up a form... 02-11-2008, 05:37 AM
  1. #1
    Registered User
    Join Date
    02-08-2008
    Posts
    35

    Issues pasting in column B and making 2nd macro available

    I have created an excel macro in VB which searches through a column of values for a given date, it then pastes the row into a second sheet. This works perfectly fine except:-

    1. I encountered problems when I tried to put a link to a macro "NewDeals" in Column A of each line, things got very messy, then paste the copied row starting at B instead of A.
    2. I also tried to set the print area to stop when there are no more values however I think it sets the print area before the macro finishes copying and pasting so it only prints my original text.
    3. I would eventually like to be able to set the date externally without having to enter the macro, I'm guessing this is quite easy so it is less important as I will probably search for an answer once everything else works ok.

    Thanks for any contributions.

    Sub Date search()
    
        Dim LSearchRow As Integer
        Dim LCopyToRow As Integer
        Dim x As Long, lastCell As Range  
    
        On Error GoTo Err_Execute
        
        LSearchRow = 4
        LCopyToRow = 7
        
        While Len(Range("A" & CStr(LSearchRow)).Value) > 0
            
            If Range("F" & CStr(LSearchRow)).Value = "06/02/2008" Then
                Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
                Selection.Copy
                Sheets("Current Deals").Select
                Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
                ActiveSheet.Paste
                LCopyToRow = LCopyToRow + 1
                Sheets("Deal History").Select
                
            End If
            
            LSearchRow = LSearchRow + 1
            
        Wend
    
        x = ActiveSheet.UsedRange.Columns.Count
        Set lastCell = Cells.SpecialCells(xlCellTypeLastCell)
        ActiveSheet.PageSetup.PrintArea = Range(Cells(1, 1), lastCell).Address
        Application.CutCopyMode = False
        Range("A3").Select
        
        
        Exit Sub
        
    Err_Execute:
        MsgBox "Something screwed up"
    
    x = ActiveSheet.UsedRange.Columns.Count
    Set lastCell = Cells.SpecialCells(xlCellTypeLastCell)
    ActiveSheet.PageSetup.PrintArea = Range(Cells(1, 1), lastCell).Address
    
    End Sub

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,523
    This workbook has quite a few examples of what you speak of..



    http://www.excelforum.com/showthread.php?t=631965
    Check out the codes in the workbook

    What do you mean by putting a link to a macro in a columns?

    as for the print code,
    you have an X variable but don't use it

  3. #3
    Registered User
    Join Date
    02-08-2008
    Posts
    35
    I've probably explained very poorly and I apologise. Thanks for the workbook though is has some useful items.

    The search and paste function works fine, and after some tinkering and actually studying the order of the commands the "set print area" is perfect now as well. So...

    I have already constructed a separate macro called "Newdeals", I would like a button for this added at the start of each row, column A, before I paste in the copied information, which would then start in column B.

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,523
    Quote Originally Posted by sungsam
    ......... I would like a button for this added at the start of each row, column A, before I paste in the copied information, which would then start in column B.
    I understand that would be really cool to do......
    there could be other alternatives,
    what would happen when the button got pressed?

  5. #5
    Registered User
    Join Date
    02-08-2008
    Posts
    35
    The macro brings up a form that I've already created, this utilises the information in that row, edits it using criteria set then saves it to a new line in another workbook.

    I know it would be neater to create the form within the macro however I already have a form I have created.

    Is it possible to link a button to a form already created or will I have to create the form anew within the macro?

  6. #6
    Registered User
    Join Date
    02-08-2008
    Posts
    35
    I thought I'd post my macro so far and hopefully that will clarify exactly what I would like to achieve.

    Sub Datesearch()
    
        Dim LSearchRow As Integer
        Dim LCopyToRow As Integer
        Dim x As Long, lastCell As Range
    
        On Error GoTo Err_Execute
        
        LSearchRow = 4
        LCopyToRow = 7
        Sheets("Deal History").Select
        
        While Len(Range("A" & CStr(LSearchRow)).Value) > 0
            
            If Range("F" & CStr(LSearchRow)).Value = "06/02/2008" Then
                S = "A" & Format(LSearchRow) & ":K" & Format(LSearchRow)
                ActiveSheet.Range(S).Select
                Selection.Copy
                Sheets("Current Deals").Select
                P = "B" & Format(LCopyToRow) & ":B" & Format(LCopyToRow)
                ActiveSheet.Range(P).Select
                ActiveSheet.Paste
                
                Sheets("Deal History").Select
                R = "R" & Format(LSearchRow) & ":R" & Format(LSearchRow)
                Range(R).Value = Range(R).Value
                ActiveSheet.Range(R).Select
                Selection.Copy
                Sheets("Current Deals").Select
                M = "M" & Format(LCopyToRow) & ":M" & Format(LCopyToRow)
                ActiveSheet.Range(M).Select
                ActiveSheet.Paste
                
                Sheets("Deal History").Select
                L = "L" & Format(LSearchRow) & ":L" & Format(LSearchRow)
                ActiveSheet.Range(L).Select
                Selection.Copy
                Sheets("Current Deals").Select
                N = "N" & Format(LCopyToRow) & ":N" & Format(LCopyToRow)
                ActiveSheet.Range(N).Select
                ActiveSheet.Paste
                
                Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
                frmNewDeals.show
                
                LCopyToRow = LCopyToRow + 1
                Sheets("Deal History").Select
                
            End If
            
            LSearchRow = LSearchRow + 1
            
        Wend
    
      
        Sheets("Current Deals").Select
        
        'Set lastCell = Cells.SpecialCells(xlCellTypeLastCell)
        'ActiveSheet.PageSetup.PrintArea = Range(Cells(1, 1), lastCell).Address
        'Application.CutCopyMode = False
        
        
        Exit Sub
        
    Err_Execute:
        MsgBox "Something screwed up"
    
    End Sub
    Within the IF I would like to add a button (or something which runs the form when u click on it) in column A of each line which opens up the form "NewDeals" when clicked. At the moment when the macro runs it opens up the form, instead of just adding a link to it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1