Consulting

Results 1 to 5 of 5

Thread: VBA coding for Excel problem

  1. #1

    VBA coding for Excel problem

    Hi

    I am trying to read a column of cells and have the content of the cell read into a variable as text.

    I am using a for next loop.

    Sub SplitCellBelowTotal()
    
    Dim i As Long
    Dim x As Long
    Dim CurrentRecord As String
    
    
    Range("A1").Select
    x = Cells(Rows.Count, 1).End(xlUp).Row
    
    
    For i = 1 To x
    
    
    CurrentRecord = Right("A" & i, 5) ' want cell text characters
    
    
    MsgBox Chr(CurrentRecord)
    
    
    If CurrentRecord = "Total" Then ActiveCell.EntireRow.Insert
    
    
    Next i
    
    
    End Sub
    Hope you understand what I am trying to do
    Last edited by Paul_Hossler; 02-12-2020 at 05:46 PM.

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    CurrentRecord = Right("A" & i, 5)
    Becomes:
    CurrentRecord = Right(Range("A" & i), 5)
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  4. #4

    Brilliant - thanks that worked.

    Quote Originally Posted by p45cal View Post
    CurrentRecord = Right("A" & i, 5)
    Becomes:
    CurrentRecord = Right(Range("A" & i), 5)

  5. #5
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    For i = 1 To x
    should be
    For i = x to 1 Step - 1

    Reason: when you insert rows. the last row becomes Row(x + 1)
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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