Excel

Simulating a Bar Chart

Ease of Use

Easy

Version tested with

97, 2000, 2002, 2003 

Submitted by:

Paleo

Description:

With this macro you may simulate a bar chart by entering values in cells. 

Discussion:

Sometimes we need to create fast and simple bar charts to show some data, this example shows how to do that by changing the cells colors, so that impression of bar chart is created. 

Code:

instructions for use

			

Option Explicit Private Sub Worksheet_Change(ByVal Target As Excel.Range) Dim i% If Target.Row <> 18 Then Exit Sub Select Case Target.Column Case 2, 3, 5, 6, 8, 9, 11, 12, 14, 15, 17, 18 If IsNumeric(Target.Value) = False Then Beep MsgBox "Only Numbers between 0 And 10 allowed!" End End If If Target.Value > 10 Or Target.Value < 0 Then Beep MsgBox "Only Numbers between 0 And 10 allowed!" End End If For i = 11 To 11 - Target.Value + 1 Step -1 With Cells(i, Target.Column) If IsEmpty(Target.Offset(0, -1)) Then .Interior.ColorIndex = 5 .Font.ColorIndex = 3 Else .Interior.ColorIndex = 3 .Font.ColorIndex = 5 End If End With Next i For i = 11 - Target.Value To 2 Step -1 With Cells(i, Target.Column) If IsEmpty(Target.Offset(0, -1)) Then .Interior.ColorIndex = xlNone .Font.ColorIndex = 3 Else .Interior.ColorIndex = xlNone .Font.ColorIndex = 3 End If End With Next i End Select End Sub

How to use:

  1. Copy the code above
  2. Open any workbook.
  3. Press Alt + F11 to open the Visual Basic Editor (VBE).
  4. Press Ctrl + R to show the Project Explorer.
  5. Double-click the worksheet where you want it to work
  6. Paste the code in it.
  7. Close the VBE and save the file
 

Test the code:

  1. Simply change the values at row 18 at the example file and you will see the result
 

Sample File:

BarChartSimulated.zip 9.85KB 

Approved by mdmackillop


This entry has been viewed 186 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express