Column clearing, incrementing and line graph plotting

FilipeF

New Member
Joined
Nov 21, 2018
Messages
1
Hi all,

Context:
1. M3 is a a variable number >0
2. The rest of columns M as well as columns N and A;J are IRRELEVANT.

Objectives:
1. I'd like to clear the columns K4 to L(Value of M3 + 2);
2. Increment the values 1 by 1 in column K. Starting with K3=0, K4=1, K5=2, ... , K(Value of M3+2)=Value of M3-1. So in this case it would be K202=199
3. Copy value from L3 through ALL lines of L till the column K stops incrementing.
4. Plot a graph from the columns K3 to L(Value of M3 + 3). Remember that the value is variable.

(IMAGE 1)
https://pasteboard.co/HOd3ocr.png
HOd3ocr.png

HOd3ocr.png


Current situation
This is the macro I have for deleting columns and then incrementing 1 by 1.

Code:
[/COLOR][COLOR=#333333]Sub IncrementB()[/COLOR]
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">Dim x, i&, ii&, j&, k&, z()
With Sheets("AidCalc1")
x = .Range("K3", .Cells(.Rows.Count, "N").End(3)).Value
ReDim z(1 To Application.Sum(Application.Index(x, 0, 3)), 1 To UBound(x, 2))
For i = 1 To UBound(x)
   If Len(x(i, 3)) Then
     k = 0
     For ii = 1 To Val(x(i, 3))
        j = j + 1
        z(j, 1) = k
        z(j, 2) = x(1, 2)
        z(j, 3) = x(i, 3)
        z(j, 4) = x(i, 4)
        k = k + 1
     Next ii
   End If
Next i
  .UsedRange.ClearContents
  .[k3].Resize(UBound(z, 1), 4) = z
End With </code>[COLOR=#333333]End Sub[/COLOR][COLOR=#333333]


Result
Besides clearing the whole sheet, which I don't want... (continues below)

(IMAGE 2)
https://pasteboard.co/HOd4Zyr.png

It is also not stopping to increment after K reaches its intended value. It goes on and on.

(IMAGE 3)
https://pasteboard.co/HOd5l70.png

Solutions needed
1. Fix clearing for the intended area instead of the whole sheet.
2. Fix incrementation to stop at the desired value on columns K and L.
3. Plot a line graph of these everchanging columns (100% NOT DONE).

Thank you in advance for your time and help!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
try these codes on a copy of your workbook and tweek it to get what you want.
Code:
Sub philip()
a = Cells(3, 13)
Range("K4:L" & a + 2).ClearContents
    For b = 4 To a
    Cells(b - 1, 11) = b - 3
    Cells(b, 12) = Cells(3, 12)
    Next b
ActiveSheet.Shapes.AddChart.Select
    ActiveChart.SetSourceData Source:=Range("$k$3:$L$" & a)
    ActiveChart.ChartType = xlLine
MsgBox "complete"
End Sub
ravishankar
 
Upvote 0

Forum statistics

Threads
1,215,255
Messages
6,123,896
Members
449,132
Latest member
Rosie14

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top