Generate Graph Based On Set of Data Using VBA

taykaisheng

New Member
Joined
Jul 30, 2013
Messages
10
Hi, i'm very new in VBA.. Currently I'm on my project which required me to creating a automation tool by plotting 2 bar chart automatically based on 2 table data as shown below
However as the table data was generated out from another automation tool thus the number of rows can be increase or decrease. And the problem was due to the number of rows could be more/less than 5, I couldn't select the cells by specifying the address of the cell such as "A7" or "B6".


And these are the expected output of the chart

Hope some kind soul could help me on this..
 
Last edited:

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
I can't see your images, but if you want to select from A1 to the last nonempty cell in column A you could use:

Code:
Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row).Select
You may also find that this works for you:

Code:
Range("A1").CurrentRegion.Select
 

taykaisheng

New Member
Joined
Jul 30, 2013
Messages
10
Thanks for your help.. However now I facing another issue. I want to create a graph based on the table data which I specified using .CurrentRegion with last row of the table data should not be included. Hope you can tell me how to do this, thank you in advance
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Example:

Code:
Sub Test()
    Dim Rng As Range
    With Range("A1").CurrentRegion
        Set Rng = .Resize(.Rows.Count - 1)
    End With
    MsgBox Rng.Address
End Sub
 

taykaisheng

New Member
Joined
Jul 30, 2013
Messages
10
Thank you for your quick response, do appreciate that a lot.. However I am facing another issue again. Let's say my CurrentRegion property consists of 3 columns A, B and C but I want to select entire column A and C as my data source for my chart, am I able to do so ? I know i can select column A and B as data source by implementing .Resize(CR.Columns.Count - 1). Thank you in advance
 

Forum statistics

Threads
1,081,470
Messages
5,358,874
Members
400,514
Latest member
JoHio2577

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top