我在切换按钮上使用此代码来隐藏/显示电子表格中的列。
function authenticate($email, $password) {
if (empty($email) || empty($password)) return false;
$auth = false;
$check = false;
$q1 = "SELECT * FROM user WHERE active = 1 ORDER BY email ASC";
$knownUsers = $this -> sql -> doMultiSelect($q1);
$checkUser = "";
foreach ($knownUsers AS $user){
if ($user ['email'] == $email) {
$check = true;
$checkUser = $user;
break;
}
if (substr($user['email'],0,1) > substr($email,0,1)) {
break;
}
}
if ($check) {
if ($checkUser['password'] == crypt($password, $email) ) {
$auth = true;
// do something with the user data
}
} else {
$this -> logActivity("failed login attempt for user ".$email);
}
return $auth;
}
此公式适用于 D:E 列。问题是,如何在此公式中添加其他列(单个和范围)?假设我需要使用相同的按钮显示/隐藏 F:K 和 N ?我尝试过像“D:E”,“F:K”这样的东西,我得到一个运行时错误。任何帮助都非常感激。
答案 0 :(得分:1)
隐藏不相交的列集的语法:
Sub dural()
Range("D:E,L:L").EntireColumn.Hidden = True
End Sub
这会隐藏 D,E,和 L 列。
答案 1 :(得分:1)
您必须使用Range对象。
Range("D:E,F:K,N:N").Select
Selection.Hidden = True
https://msdn.microsoft.com/en-us/library/office/ff838238.aspx
<强>更新强>
您的代码应如下所示:
Sub Button22_Click()
Range("D:E,F:K,N:N").Select
Selection.EntireColumn.Hidden = Not Selection.EntireColumn.Hidden
End Sub