Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6888403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:00:40+00:00 2026-05-27T06:00:40+00:00

I am attempting to copy and paste text values to a certain amount of

  • 0

I am attempting to copy and paste text values to a certain amount of cells in excel based on a text comparison.

Please see below for explanation:

I have 2 column A(blank) and B(with values)

enter image description here

After the macros, this will be the end results:

enter image description here

It is basically taking the bottom cell after it detect the fruits column and pasting the cell value into row A. Note that after it reaches the next cell fruits it take the next (bottom) cell value. F123,F124 etc..

Can someone please provide me with the excel vba codes to do? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:00:40+00:00Added an answer on May 27, 2026 at 6:00 am

    I would not use VBA for this problem. I would type:

    =IF(AND(LEFT(B2,1)="F",B2<>"Fruits"),B2,A1)
    

    into A2 and copy down. This seems to give the effect you seek.

    If you really want to use VBA, the tested code is:

    Dim CellValue As String
    Dim RowCrnt As Integer
    Dim RowMax As Integer
    
    With Sheets("Sheet1")   ' Replace Sheet1 by the name of your sheet
      RowMax = .Cells(Rows.Count, "B").End(xlUp).Row
      For RowCrnt = 2 To RowMax
        CellValue = .Cells(RowCrnt, 2).Value
        If Left(CellValue, 1) = "F" And CellValue <> "Fruits" Then
          .Cells(RowCrnt, 1).Value = CellValue
        Else
          .Cells(RowCrnt, 1).Value = .Cells(RowCrnt - 1, 1).Value
        End If
      Next
    End With
    

    The following explains those aspects of the above code that may be obscure to a newbie.

    The macro recorder almost always uses Range(“A5”) or Range(“A5:C10”) to refer to ranges.

    There appear to be a few commands (sorry, don’t remember which) for which this format is compulsory but for most purposes Cells(Row, Column) is more convenient.

    If you want to add 1 to every numeric value in the range “A5:C10” of sheet “Sheet1”, the following shows how to do this with Cells:

    Dim CellValue as String
    Dim ColCrnt As Integer
    Dim RowCrnt As Integer
    
    With Sheets("Sheet1")
      For RowCrnt = 5 to 10
        For ColCrnt = 1 to 3    ' "A" to "C"
          CellValue = .Cells(RowCrnt, ColCrnt).Value
          If IsNumeric(CellValue) Then
            .Cells(RowCrnt, ColCrnt).Value = CellValue + 1           
          End If
        Next
      Next
    End With
    

    There is a time penalty with accessing cells in a worksheet but I have used CellValue more because code can get very cluttered with too many cell references.

    Note: in “A5” the column comes first but in Cells(5,1) the row comes first.

    You can define ranges with Cells. The following sets “A5:C10” of the active sheet to bold:

    Range(Cells(5,1), Cells(10,3)).Font.Bold = True
    

    To address column A of the last row of the active sheet:

    Cells(Rows.Count,"A")
    

    To address the last column of row 1:

    Cells(1,Columns.Count)
    

    Ctrl+Up, Ctrl+Down, Ctrl+Left and Ctrl+Right can be used to jump from an empty cell to the next cell with a value in the indicated direction. You can do the same in VBA. But more usefully you can get the value of the row or column to which the cursor would jump without the time penalty of moving the cursor.

    If the cursor was in column B of the last row and you pressed Ctrl+Up, the cursor would jump to the last row with a value in column B. The following sets RowMax to that row number for the active sheet:

    RowMax = Cells(Rows.Count, "B").End(xlUp).Row
    

    To get the last used column of row 27:

    ColMax = Cells(27,Columns.Count).End(xlToRight).Column  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to copy cells, one at a time, from an Excel 2003 (or
Attempting to copy/paste a 159KB TSQL query into Microsoft Access 2010 passthrough query editor
I'm attempting to use the adb pull command to copy only certain files (jpg)
I am attempting to insert a copy of a row from one table into
When attempting to commit file in the jsunit directory in my working-copy, I waited
Attempting to print out a list of values from 2 different variables that are
When attempting to create a tag of a working copy we receive the error,
I'm attempting to compile a working copy of the MagickNet class library (DLL) using
I'm attempting a simple test of binary file I/O using the STL copy algorithm
I am trying to copy some property values from one object to another (both

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.