+ Reply to Thread
Results 1 to 7 of 7

Adjusting VBA code to go to first free cell down

Hybrid View

  1. #1
    Registered User
    Join Date
    12-13-2011
    Location
    Sofia, Bulgaria
    MS-Off Ver
    Excel 2010
    Posts
    68

    Adjusting VBA code to go to first free cell down

    Hi all,

    I write with the following problem: I wrote a VBA code in Excel but I cannot adjust some things and I will be grateful if you can help me. So, can be added to vba code to do the following:
    1. Macros FillPrices - after filling data to go to first free cell to be ready for use next day.
    2. Macros FillPrices - after filling data conditionanally formating in red if used formula (true condition of IF operator).
    3. Macros FillIndices - after filling data to go to first free cell to be ready for use next day.

    I attach an example file.

    Thanks in advance.
    Attached Files Attached Files
    Last edited by geri_n; 12-22-2011 at 03:58 AM.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Adjusting VBA code to go to first free cell down

    I have a couple of questions -
    1. Your file has several tabs. On which sheet should the macro go to the first free cell?
    2. After going thru ur code, its apparent that you want the paste special function to be performed in certain sections of your file and there could be some other actions too. If you explain it to me, i can help you better your code.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    12-13-2011
    Location
    Sofia, Bulgaria
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Adjusting VBA code to go to first free cell down

    Hi Arlu,

    My purpose is to change data in Buletin tab and run FillPrices macros to fill data in ten other tabs (without PAZAR sheet). For this 10 tabs is other purpose toconditionanally formating in red if used formula (true condition of IF operator).
    2. Paste Special (in FillIndices macros) is for PAZAR sheet and this is related to my question 3.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Adjusting VBA code to go to first free cell down

    For 1 & 2:
    Sub FillPrices()
        
        With ActiveCell
            .FormulaR1C1 = _
                "=IF(VLOOKUP(R1C3,Buletin!C[-2]:C[9],8,0)=0,R[-1]C,VLOOKUP(R1C3,Buletin!C[-2]:C[10],13,0))"
            .Value = .Value
            If .Value = .Offset(-1).Value Then .Font.ColorIndex = 3
            .Offset(1).Select
        End With
    
    End Sub

    For #3, this will select the next empty row and confirm with you before proceeding:
    Sub FillIndices()
    Dim NextRow As Long
    
    With Sheets("PAZAR")
        NextRow = .Range("C" & .Rows.Count).End(xlUp).Offset(1).Row
        If MsgBox("Adding data to Period " & .Range("A" & NextRow).Value _
            & " ... proceed?", vbYesNo, "Confirm") = vbNo Then Exit Sub
            
        .Range("C" & NextRow).Value = Sheets("Buletin").Range("J11").Value
        .Range("H" & NextRow).Value = Sheets("Buletin").Range("J12").Value
        .Range("M" & NextRow).Value = Sheets("Buletin").Range("J14").Value
        .Range("R" & NextRow).Value = Sheets("Buletin").Range("J13").Value
    End With
    
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Adjusting VBA code to go to first free cell down

    If you want the FillPrices to automatically do all the sheets, try this:
    Sub FillPrices()
    Dim Period As Long, Guess As Long, ws As Worksheet, PeriodRNG As Range
    
    Guess = Sheets("ALB").Range("C" & Rows.Count).End(xlUp).Offset(1, -2).Value
    
    Period = Application.InputBox("What period to process?", "Period", Guess, Type:=1)
    If Period = 0 Then Exit Sub
    On Error Resume Next
    
    For Each ws In Worksheets
        If ws.Name <> "Buletin" And ws.Name <> "PAZAR" Then
            With ws
                Set PeriodRNG = .Range("A:A").Find(Period, LookIn:=xlValues, LookAt:=xlWhole)
                If Not PeriodRNG Is Nothing Then
                    With PeriodRNG.Offset(, 2)
                        .FormulaR1C1 = _
                            "=IF(VLOOKUP(R1C3,Buletin!C[-2]:C[9],8,0)=0,R[-1]C,VLOOKUP(R1C3,Buletin!C[-2]:C[10],13,0))"
                        .Value = .Value
                        If .Value = .Offset(-1).Value Then .Font.ColorIndex = 3
                    End With
                    Set PeriodRNG = Nothing
                End If
            End With
        End If
    Next ws
    
    End Sub

  6. #6
    Registered User
    Join Date
    12-13-2011
    Location
    Sofia, Bulgaria
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Adjusting VBA code to go to first free cell down

    Your code looks good, but does not start with me and I'm not sure whether there were the settings but I can not check them.
    Will it be many arrogantly on my part if I asked you to attach the file with your corrections
    Last edited by geri_n; 12-22-2011 at 03:57 AM.

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Adjusting VBA code to go to first free cell down

    ...but does not start with mean...
    What are you asking here? I don't understand that.

    You can copy my macros into your module to replace your macros, or change the name(s) of the macros and add them into a separate module to test separate from your original macros. You know which module I mean?

+ 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