简体   繁体   English

Excel中的一些条件编程

[英]Some conditional programming in Excel

I am trying to build a little workout log in Excel. 我正在尝试在Excel中建立一些锻炼日志。 I have a drop down list that allows me to pick which muscle group I exercised that day(legs, chest, back, etc.) and I have unique spreadsheet for each group in different worksheets. 我有一个下拉列表,可让我选择当天进行锻炼的肌肉群(腿,胸部,背部等),并且在不同的工作表中每个组都有唯一的电子表格。 I am wanting to be able to choose a muscle group and have that specific spreadsheet pop up right next to it. 我希望能够选择一个肌肉组,并在其旁边弹出特定的电子表格。

Is this possible? 这可能吗? Will it also bring over any formatting/borders? 还会带来任何格式/边界吗?

Thanks 谢谢

Try this for an idea for you to refine further. 尝试使用此方法,以供您进一步完善。 I have assumed two worksheets and an ActiveX combobox, which I have called cmbMGrp , on worksheet 1 (WorkOut). 我假设在工作表1(WorkOut)上有两个工作表和一个ActiveX组合框,我将其称为cmbMGrp

One called WorkOut 一个叫做WorkOut

标签锻炼 This contains your combobox 'dropdown' and the area to the right for the exercise schedule. 这包含您的组合框“下拉列表”以及锻炼计划右侧的区域。

and one called Exercises 还有一个叫做练习

制表练习 This contains the exercise schedule for each muscle group. 这包含每个肌肉群的锻炼计划。

Add the following two bits of code to the Sheet module (WorkOut) ie the sheet that contains the combobox. 将以下两位代码添加到工作表模块(WorkOut),即包含组合框的工作表。

Private Sub cmbMGrp_Change()

    Select Case cmbMGrp.Value
        Case Is = "Biceps"
            stCol = 1
        Case Is = "Legs"
            stCol = 5
        Case Is = "Chest"
            stCol = 9
        Case Is = "Back"
            stCol = 13
        Case Else
            stCol = 0
    End Select

    If stCol > 0 Then
        With Sheets("Exercises")
            lrow = .Cells(Rows.Count, stCol).End(xlUp).Row
            .Range(.Cells(1, stCol), .Cells(lrow, stCol).Offset(0, 2)).Copy _
                  Destination:=Sheets("Workout").Range("I3")
        End With
    End If
End Sub

Private Sub cmbMGrp_GotFocus()
    With Sheets("Workout")
        lrow = .Cells(Rows.Count, 9).End(xlUp).Row
        .Range(.Cells(3, 9), .Cells(lrow, 9).Offset(0, 2)).Clear
    End With
End Sub

You should be able to match the code to the layouts I have used for this example, shown in the images. 您应该能够将代码与我在此示例中使用的布局相匹配,如图所示。 Change these to suit your requirements. 更改这些以适合您的要求。

I think that for your task, you should forget dropdowns. 我认为对于您的任务,您应该忘记下拉菜单。 Simply make one table, with rows corresponding to the days, and columns to exercises. 只需制作一张表格,其中的行对应于日期,而列则对应于练习。 You can easily group exercises by muscle groups. 您可以按肌肉组轻松地对运动进行分组。 Eg. 例如。 leg might contain flexors, extensors (quadriceps), ass (gluteus), calf (gastrocnemius) etc. Or you can name exercises by the machines you use. 腿部可能包含屈肌,伸肌(股四头肌),屁股(臀肌),小腿(腓肠肌)等。或者,您可以根据使用的机器来命名锻炼。 Keep it simple in one table, too much programming will distract you from your health effort, which is your real goal. 将其保持在一张表中很简单,太多的编程会使您分心,这是您的真正目标。

Btw. 顺便说一句。 I'm quite good in Excel and have done quite amazing things with it, but I tell you, if you value your physical fitness, stay away from its Visual Basic. 我在Excel中相当出色,并且在它方面做得非常出色,但是我告诉您,如果您重视身体健康,请远离它的Visual Basic。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM